php 在 Woocommerce 中显示客户订单评论(客户备注)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27144737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:12:38  来源:igfitidea点击:

Display Customer order comments (customer note) in Woocommerce

phpwordpresswoocommercemessageorders

提问by Nick

I have a little problem when I try to display woocommerce customer order comments (not the notes, but the comments that a customer can add during the checkout process).

当我尝试显示 woocommerce 客户订单评论(不是注释,而是客户可以在结账过程中添加的评论)时,我遇到了一个小问题。

(I'm going to add just the relative lines for this problem, as other woocommerce data is correctly displayed so it shouldn't be a setup problem).

(我将仅添加此问题的相关行,因为其他 woocommerce 数据已正确显示,因此它不应该是设置问题)。

What I've tried so far is this:

到目前为止我尝试过的是:

$notes = $order->get_customer_order_notes(); //This line returns an Array[]

Inside that array, this is the field that I think I need, as it contains my order comment:

在该数组中,这是我认为需要的字段,因为它包含我的订单注释:

$notes
  0={stdClass} 38
    post_excerpt = "test"

and so what I did is trying to display this value like this:

所以我所做的是尝试像这样显示这个值:

echo "Order Notes: " . $notes->post_excerpt

but unfortunately the result is empty.

但不幸的是结果是空的。

What am I doing wrong? Many thanks

我究竟做错了什么?非常感谢

回答by Nick

Ok, after some time spent on trying, I finally find out that the right way to display the customer checkout comment is selecting $order->customer_message;and set this value as variable.

好的,经过一段时间的尝试,我终于发现显示客户结帐评论的正确方法是选择$order->customer_message;并将此值设置为变量。

回答by LoicTheAztec

Update 2017 - 2018 | For Woocommerce 3+

2017 - 2018 更新 | 对于 Woocommerce 3+

Since Woocommerce 3 you can't access anymore properties From the WC_Orderobject. You need to use the WC_Ordermethod get_customer_note()instead:

从 Woocommerce 3 开始,您无法再访问WC_Order对象中的属性。您需要改用该WC_Order方法get_customer_note()

$customer_note = $order->get_customer_note();

Related:
Display order customer note in Woocommerce email notifications
Add order customer note to YITH Woocommerce PDF Invoice

相关:
在 Woocommerce 电子邮件通知中显示订单客户备注
将订单客户备注添加到 YITH Woocommerce PDF 发票