在 Woocommerce 中,我试图向客户获取额外的订单消息:
我正在尝试在电子邮件通知上显示该客户消息。
但我不知道如何在 php 代码中获取这些信息。
这是我在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>';
}
我真的不知道如何访问该信息。
任何帮助表示赞赏。
您的代码中有一些错误。使用WC_Order
method 获取客户备注() https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html#_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;
}
代码位于活动子主题(活动主题)的 function.php 文件中。经过测试并有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)