简体   繁体   English

在 Woocommerce 电子邮件通知中显示订单客户备注

[英]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.

相关问题 在Woocommerce中显示客户订单评论(客户备注) - Display Customer order comments (customer note) in Woocommerce 在“新订单” Woocommerce电子邮件通知中显示客户电话 - Display customer phone in “New Order” Woocommerce email notifications 在Woocommerce管理员电子邮件通知中显示购买记录 - Display purchase note in Woocommerce admin email notifications 定位WooCommerce客户处理和完成的订单电子邮件通知 - Targetting WooCommerce customer processing and completed order email notifications 添加文本到 WooCommerce 客户完成订单 email 基于运输和订单备注 - Add a text to WooCommerce customer complete order email based on shipping and order note 在 WooCommerce 中为新客户订单添加订单备注 - Add order note to new customer orders in WooCommerce 在 Woocommerce 电子邮件通知中显示自定义订单状态的付款链接 - Display a payment link for custom order statuses in Woocommerce email notifications 在 WooCommerce email 通知上下载前显示订单详细信息 - Display Order details before downloads on WooCommerce email notifications 在 WooCommerce 订单 email 通知中显示已使用的优惠券 - Display used coupon(s) in WooCommerce order email notifications 在 email 通知中显示自定义订单元数据值 WooCommerce - Display custom order meta data value in email notifications WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM