Display order customer note in Woocommerce email notifications

僤鯓⒐⒋嵵緔 提交于 2019-12-06 12:55:18

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:

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). Tested and works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!