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

时间:2018-10-03 21:27:01

标签: php wordpress woocommerce hook-woocommerce email-notifications

在Woocommerce中,我试图为客户提供其他订单消息:

Screenshot

我正在尝试在电子邮件通知中显示该客户消息。 但是我不知道如何在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>';
}

我真的不知道如何访问该信息。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您的代码中有一些错误。使用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文件中。经过测试,可以正常工作。

enter image description here

相关问题