php - 将订单客户备注添加到 YITH Woocommerce PDF 发票
问题描述
在 Woocommerce 中,我使用了一个名为YITH WooCommerce PDF Invoice and Shipping List的插件,我想在 PDF 发票中添加客户备注。
我想在下面代码的第一行之后添加它:
<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
变量中获取客户注释。
我曾尝试使用此答案线程:“在 Woocommerce 中显示客户订单评论(客户备注) ”,这看起来很像同样的问题,但仍然无法弄清楚它$document->order->customer_message;
不起作用。
任何帮助表示赞赏。
解决方案
自 Woocommerce 3 以来,您无法再从WC_Order
对象访问属性。您需要使用WC_Order
方法 [ get_customer_note()
][1]。
因此,$document
您将使用(YITH 全局对象):
$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 文件中。未经测试(因为我没有插件的高级版本),但它应该可以正常工作(取决于插件设置)。
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
它应该工作。
对于免费插件版本
- 没有可用的钩子(就像在提供的代码中一样)......</li>
- 需要调用YITH PDF 全局对象,而不是
$document
.
因此,您将能够在templates/invoice/invoice-footer.php
模板中使用以下代码:
<?php global $ywpi_document; echo $ywpi_document->order->get_customer_note(); ?>
推荐阅读
- macos - 如何在 mac 上的 odoo 14 中配置自定义插件路径?
- r - 在 R 中有一列具有 205550 个值,并且想要 10 列,其中值 1 进入第 1 列,值 2 进入第 2 列等
- python - 如何在 django 中创建一个传入多个对象的字典的自定义模板标签
- rmi - RMI 中的存根和 RPC 中的存根有什么区别?
- sql - 将带有信息的 Varchar 拆分为表格
- unity3d - 如何在不使用 public 的情况下编写脚本?
- python - 使用 Pandas 进行 JSON 到 Excel 的转换是将整个 JSON 文件放在 1 个 Excel 单元格中
- visual-studio - Unity - TextMeshPro 文本对象不更新
- rust - 使用可变引用覆盖变量时借用检查器错误
- javascript - Edge、Mozilla、Chrome 中的闪烁问题