首页 > 解决方案 > 如何向管理员和客户发送暂停的 WooCommerce 电子邮件通知

问题描述

默认情况下,WooCommerce 仅向客户发送 On-Hold 订单通知(不知道为什么,因为似乎让商店经理知道订单何时被搁置非常重要......)

我已经尝试根据我在这里和谷歌上发现的研究线程在我的子主题的functions.php中实现以下片段:向管理员发送暂停订单状态电子邮件通知

add_filter( 'woocommerce_email_headers', 'custom_admin_email_notification', 10, 3);
function custom_admin_email_notification( $headers, $email_id, $order ) {

    if( 'customer_on-hold_order' == $email_id ){
        // Set HERE the Admin email
        $headers .= 'Bcc: My name <my@email.com>\r\n';
    }
    return $headers;
}

我还尝试了来自同一线程的以下代码段:

// Send on-hold order status email notification to admin
add_filter( 'woocommerce_email_headers', 'custom_admin_email_notification', 10, 3);
function custom_admin_email_notification( $headers, $email_id, $order ) {

    if( strpos($email_id,'hold') > 0 ){
        $headers .= 'Bcc: Admin User <admin@example.com>'. "\r\n";
    }
    return $headers;
}

当订单从待付款更改为暂停时,这些似乎都不起作用。是的,我已将片段中的电子邮件更改为我的管理员电子邮件。我正在寻找一种解决方案,当这种情况自动发生(从待付款到暂停)或在编辑订单时手动发生时,管理员将在客户暂停电子邮件中被密件抄送。

标签: phpwordpresswoocommerceemail-notifications

解决方案


  • 添加utf8_decode可能会有所帮助
  • 替换customer_on-hold_ordercustomer_on_hold_order
  • 使用 Wordpress 5.8.1 和 WooCommerce 5.6.0 测试

所以你得到:

function filter_woocommerce_email_headers( $header, $email_id, $order ) {
    // Compare
    if ( $email_id == 'customer_on_hold_order' ) {      
        // Prepare the the data
        $formatted_email = utf8_decode( 'My test <my_test@email.com>' );

        // Add Bcc to headers
        $header .= 'Bcc: ' . $formatted_email . '\r\n';
    }

    return $header;
}
add_filter( 'woocommerce_email_headers', 'filter_woocommerce_email_headers', 10, 3 );

推荐阅读