向管理员发送暂停订单状态电子邮件通知

4
我希望管理员在WooCommerce中也能收到“待处理”订单通知。目前,只有客户会收到这个通知。
我尝试过以下代码,但似乎没有起作用。
这是我的代码:
add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
function mycustom_headers_filter_function( $headers, $object ) {
    if ($object == 'customer_on_hold_order') {
        $headers .= 'BCC: My name <my@email.com>' . "\r\n";
    }
    return $headers;
}

应该使用哪个正确的过滤器/钩子?

谢谢

3个回答

2

“on-hold”订单状态电子邮件通知的正确$email_id'customer_on-hold_order'

因此,您的代码将是:

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;
}

代码放在您的活动子主题(或主题)或任何插件文件中的function.php文件中。

代码已经测试并可用。


类似的答案:如何在woocommerce_email_headers钩子中获取订单ID


这个能否修改以适用于发送给客户的其他状态? - Wali Muhammad Khubaib
@WaliMuhammadKhubaib 是的,它可以 - 一些其他相关的答案:https://stackoverflow.com/search?q=user%3A3730754+email_id - LoicTheAztec

0

已经过去了3年,WooCommerce的状态似乎已经改变。我尝试使用新的状态customer_on-hold_order => pending_to_on-holdwoocommerce_order_status_pending_to_on-hold,但没有收到任何电子邮件,标题也没有改变。所以我最终只使用单词进行检查:

// 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;
}

感谢您,@LoicTheAztec,指引我朝着正确的方向。


0

关于“待处理”订单状态电子邮件通知的正确$email_id不是下面回答中建议的'customer_on-hold_order'(抱歉没有声望进行评论),而是'customer_on_hold_order'

因此,请将'on-hold'更改为'on_hold'


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接