在 Woocommerce 电子邮件通知中显示订单客户备注
Display order customer note in Woocommerce email notifications
在 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
方法 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 文件。已测试并有效。
在 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
方法 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 文件。已测试并有效。