【问题标题】:Add order customer note to YITH Woocommerce PDF Invoice将订单客户备注添加到 YITH Woocommerce PDF 发票
【发布时间】:2018-10-20 00:40:56
【问题描述】:

在 Woocommerce 中,我使用了一个名为 YITH WooCommerce PDF Invoice and Shipping List 的插件,我想在 PDF 发票中添加客户备注。

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

        <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 变量中获取客户备注。

我曾尝试使用这个答案线程:“Display Customer order comments (customer note) in Woocommerce”,它看起来很像同样的问题,但仍然无法弄清楚,因为$document-&gt;order-&gt;customer_message; 不起作用。

感谢任何帮助。

【问题讨论】:

    标签: php wordpress pdf woocommerce invoice


    【解决方案1】:

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

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

    $document->order->get_customer_note();
    

    要将客​​户备注添加到 YITH 发票,您可以选择以下两种方式:

    1) 使用可用的yith_ywpi_after_document_notes action hook

    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 文件中。未经测试(因为我没有插件的高级版本),但它应该可以正常工作(取决于插件设置)

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

        <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

    这样您就可以在templates/invoice/invoice-footer.php 模板中使用以下代码:

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

    【讨论】:

    • 非常感谢,非常有帮助,而且效果很好.. :)
    猜你喜欢
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 2016-08-02
    • 2021-10-27
    • 2020-05-01
    相关资源
    最近更新 更多