[英]Display order customer note in Woocommerce email notifications
In Woocommerce, I am trying to get the customers additional order message:在 Woocommerce 中,我试图让客户获得额外的订单消息:
I am trying to display that customer message on the email notifications.我正在尝试在电子邮件通知中显示该客户消息。 But i don't know how to get this information in the php code.
但我不知道如何在 php 代码中获取这些信息。
Here is my code in the functions.php file:这是我在functions.php文件中的代码:
add_action( 'woocommerce_email_after_order_table', 'ts_email_after_order_table', 10, 4 );
function ts_email_after_order_table( $item_id, $item, $order, $plain_text){
$notes=$order->customer_message; //did not work
echo '<table cellspacing="0" cellpadding="0" style="width: 100%; color: #636363; border: 1px solid #e5e5e5;" border="0"><tbody><tr><td><p>Test: ' . $notes . '</p></td></tr></tbody></table>';
}
I really don't know how to access that information.我真的不知道如何访问这些信息。
Any help is appreciated.任何帮助表示赞赏。
There are some errors in your code.您的代码中有一些错误。 Using the
WC_Order
method get_customer_note() , try the following instead, that will display for some successful email notifications, the customer order note:使用
WC_Order
方法get_customer_note() ,尝试以下操作,这将显示一些成功的电子邮件通知,客户订单注释:
add_action( 'woocommerce_email_after_order_table', 'customer_note_email_after_order_table', 10, 4 );
function customer_note_email_after_order_table( $order, $sent_to_admin, $plain_text, $email ){
// Only on some email notifications
if ( in_array( $email->id, array('new_order', 'customer_on_hold_order', 'customer_processing_order', 'customer_completed_order') ) ) :
// Get customer Order note
$customer_note = $order->get_customer_note();
// Display the Customer order notes section
echo '<h2>' . __("Order notes", "woocommerce") . '</h2>
<div style="margin-bottom: 40px;">
<table cellspacing="0" cellpadding="0" style="width: 100%; color: #636363; border: 2px solid #e5e5e5;" border="0">
<tr><td><p>' . $customer_note . '</p></td></tr>
</table></div>';
endif;
}
Code goes in function.php file of your active child theme (active theme).代码位于活动子主题(活动主题)的 function.php 文件中。 Tested and works.
测试和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.