如何向管理员和客户发送暂停的 WooCommerce 电子邮件通知

How can I send on-hold WooCommerce email notification to admin as well as customer

默认情况下,WooCommerce 只向客户发送暂停订单通知(不知道为什么,因为让商店经理知道订单何时暂停似乎非常重要...)

我已尝试根据我在此处和 Google 上发现的研究线索,将以下片段实施到我的子主题 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;
}

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

  • 添加 utf8_decode 可能会有帮助
  • customer_on-hold_order替换为customer_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 );