将订单客户注释添加到YITH Woocommerce PDF发票 [英] Add order customer note to YITH Woocommerce PDF Invoice

查看:172
本文介绍了将订单客户注释添加到YITH Woocommerce PDF发票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Woocommerce中,我使用的插件名为 YITH WooCommerce PDF发票和发货清单,我想在PDF发票中添加客户注释.

In Woocommerce I am using a plugin called YITH WooCommerce PDF Invoice and Shipping List and I would like to add customer note to the PDF invoice.

我想在下面的代码的第一个跨距行之后添加它:

I would like to add it after the first span line in the code below:

        <span class="notes-title"><?php _e( "Notes", "yith-woocommerce-pdf-invoice" ); ?></span>    
        <div class="notes">
            <span><?php echo nl2br( $notes ); ?></span>
            <?php do_action( 'yith_ywpi_after_document_notes', $document );?>
        </div>
    </div>
    <?php

但是我不知道如何从$document变量获取客户注释.

But i can't figure out how to get the customer note from $document variable.

我尝试使用此答案线程:"在Woocommerce中显示客户订单注释(客户注释)",该问题看上去很像相同的问题,但由于$document->order->customer_message;不起作用,仍然无法解决.

I have tried to use this answer thread: "Display Customer order comments (customer note) in Woocommerce" which looks pretty much like the same problem but still could'nt figure it out as $document->order->customer_message; doesn't work.

感谢您的帮助.

推荐答案

自Woocommerce 3以来,您无法再从WC_Order对象访问属性.您需要使用WC_Order方法[get_customer_note()] [1].

Since Woocommerce 3 you can't access anymore properties From the WC_Order object. You need to use the WC_Order method [get_customer_note()][1].

因此,在$document(YITH全局对象)中,您将使用:

So from the $document (YITH global object) you will use:

$document->order->get_customer_note();

要在YITH发票中添加客户注释,您可以选择以下两种方式:

1)使用可用的yith_ywpi_after_document_notes 动作挂钩:

add_action( 'yith_ywpi_invoice_template_products_list', 'add_customer_notes_after_document_notes', 5 );
function add_customer_notes_after_document_notes( $document ) {
    ?><span><?php echo $document->order->get_customer_note(); ?></span><?php
}

代码进入您的活动子主题(或活动主题)的function.php文件中.未经测试的(因为我没有该插件的高级版本),但它应该可以正常运行(取决于插件设置).

Code goes in function.php file of your active child theme (or active theme). Untested (as I dont have the premium version of the plugin) but it should work normally (depending on the plugin settings).

2)覆盖模板(在您提供的代码中):

2) Overriding templates (in your provided code):

    <span class="notes-title"><?php _e( "Notes", "yith-woocommerce-pdf-invoice" ); ?></span>    
    <div class="notes">
        <span><?php echo nl2br( $notes ); ?></span>
        <span><?php echo $document->order->get_customer_note(); ?></span>
        <?php do_action( 'yith_ywpi_after_document_notes', $document );?>
    </div>
</div>
<?php

应该可以.

免费插件版本

  • 没有可用的钩子(如提供的代码中所示)…
  • YITH PDF全局对象需要被调用,而不是$document.
    • There is no available hooks (like in the provided code)…
    • The YITH PDF global object need to be called and it's not $document.
    • 因此,您将能够在templates/invoice/invoice-footer.php模板中使用以下代码:

      So you will be able to use the following code in templates/invoice/invoice-footer.php template:

       <?php global $ywpi_document; echo $ywpi_document->order->get_customer_note(); ?>
      

      这篇关于将订单客户注释添加到YITH Woocommerce PDF发票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆