代码之家  ›  专栏  ›  技术社区  ›  plonknimbuzz

如何在商务中停止向特定用户发送电子邮件?

  •  0
  • plonknimbuzz  · 技术社区  · 6 年前

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

    <?php
    add_filter( 'woocommerce_email_headers', 'ieo_ignore_function', 10, 2);
    
    function ieo_ignore_function($headers, $email_id, $order) {
        $list = 'admin@example.com,cs@example.com';
        $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' ) );
            }
        }
    }
    

    但是我一直在发邮件。我试图在Woocommerce文档和源代码(github)以及Stackoverflow中搜索,但仍然无法解决这个问题。

    0 回复  |  直到 6 年前
        1
  •  2
  •   LoicTheAztec    6 年前

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

    // 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('jack@mail.com','emma@mail.com') ) ){
            $recipient = '';
        }
        return $recipient;
    }
    

    代码进入函数.php活动子主题的文件(活动主题)。测试和工作。

    过滤器挂钩需要 筛选的主函数参数


    也可以从 组成员的用户号 比如:

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


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

        2
  •  0
  •   OnGe    4 年前

    虽然上面的答案是有效的,但这似乎是一个更严格的解决方案:

    add_filter( 'woocommerce_email_recipient_customer_completed_order', 'completed_email_recipient_customization', 10, 2 );
    function completed_email_recipient_customization( $recipient, $order ) {
        if( in_array($recipient, ['some@email2block.com', 'another@email2block.com'] ) ) {
            $recipient = '';
        }
        return $recipient;
    }