停止发送Woocommerce中特定用户的特定电子邮件通知

问题描述 投票:0回答:1

我想停止发送特定用户/电子邮件的Woocommerce电子邮件。这是我的示例代码,用于在订单完成时停止发送电子邮件。

<?php
add_filter( 'woocommerce_email_headers', 'ieo_ignore_function', 10, 2);

function ieo_ignore_function($headers, $email_id, $order) {
    $list = '[email protected],[email protected]';
    $user_email = (method_exists( $order, 'get_billing_email' ))? $order->get_billing_email(): $order->billing_email;
    $email_class = wc()->mailer();
    if($email_id == 'customer_completed_order'){
        if(stripos($list, $user_email)!==false){
            remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
        }
    }
}

但WP继续发送电子邮件。我尝试搜索Woocommerce文档和源代码(github)和Stackoverflow,但仍然无法解决这个问题。

php wordpress woocommerce orders email-notifications
1个回答
2
投票

在此示例中,“客户已完成订单”通知对特定客户电子邮件地址禁用:

// Disable "Customer completed order" for specifics emails
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'completed_email_recipient_customization', 10, 2 );
function completed_email_recipient_customization( $recipient, $order ) {
    // Disable "Customer completed order
    if( is_a('WC_Order', $order) && in_array($order->get_billing_email(), array('[email protected]','[email protected]') ) ){
        $recipient = '';
    }
    return $recipient;
}

代码位于活动子主题(活动主题)的function.php文件中。经过测试和工作。

注意:过滤器钩子总是需要返回过滤的main函数参数


它也可以通过以下用户ID来完成:

// Disable "Customer completed order" for specifics User IDs
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'completed_email_recipient_customization', 10, 2 );
function completed_email_recipient_customization( $recipient, $order ) {
    // Disable "Customer completed order
    if( is_a('WC_Order', $order) && in_array($order->get_customer_id(), array(25,87) ) ){
        $recipient = '';
    }
    return $recipient;
}

代码位于活动子主题(活动主题)的function.php文件中。经过测试和工作。


类似:Stop specific customer email notification based on payment methods in Woocommerce

© www.soinside.com 2019 - 2024. All rights reserved.