在 Woocommerce 管理员电子邮件通知中显示购买备注

Display purchase note in Woocommerce admin email notifications

我在我的 functions.php 文件中使用一个函数来显示 Woocommerce 客户电子邮件中的产品购买备注。它看起来像这样:

function sww_add_note_woocommerce_emails( $output, $order ) {

    // set a flag so we don't recursively call this filter
    static $run = 0;

    // if we've already run this filter, bail out
    if ( $run ) {
        return $output;
    }

    $args = array(
        'show_purchase_note'    => true,
    );

    // increment our flag so we don't run again
    $run++;

    // if first run, give WooComm our updated table
    return wc_get_email_order_items( $order, $args );
}
add_filter( 'wc_get_email_order_items', 'sww_add_note_woocommerce_emails', 10, 2 );

这非常适合客户收到的电子邮件,但我还希望它显示管理员收到的 'new order' 电子邮件中的注释。

他们都使用相同的顺序 table 所以我不确定为什么它不起作用。

我没有找到 wc_get_email_order_items 的挂钩,而是找到了带有其他一些挂钩的函数。改为尝试:

add_filter( 'woocommerce_email_order_items_args', 'display_customer_note_in_all_emails', 10, 1 );
function display_customer_note_in_all_emails( $args ) {
    $args['show_purchase_note'] = true;

    return $args;
} 

代码进入您的活动子主题(或活动主题)的 function.php 文件。它应该有效。