【问题标题】:How to add BCC recipient to all emails sent by WooCommerce?如何将密件抄送收件人添加到 WooCommerce 发送的所有电子邮件中?
【发布时间】:2019-03-26 05:22:06
【问题描述】:

我正在尝试将密件抄送添加到 woocommerce / wp 发送的每封邮件中。我尝试使用在网上和 Stackoverflow 上找到的不同解决方案,并将 sn-ps 添加到我正在使用的主题的 functions.php 中:

add_filter( 'woocommerce_email_headers', 'add_bcc_to_wc_admin_new_order', 10, 3 );
function add_bcc_to_wc_admin_new_order( $headers = '', $id = '', $wc_email = array() ) {
    if ( $id == 'new_order' ) {
        $headers .= "Bcc: my@mail.net\r\n";
    }
return $headers;
}

add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 2);

function add_bcc_all_emails($headers, $object) {

    $headers = array();
    $headers[] = 'Bcc: my@mail.net';
    $headers[] = 'Content-Type: text/html';

    return $headers;
}

add_filter('wp_mail','custom_mails', 10,1);

function custom_mails($args){
    $bcc_email = sanitize_email('my@mail.net');

    if (is_array($args['headers'])){
        $args['headers'][] = 'Bcc: '.$bcc_email ;
    }
    else{
        $args['headers'] .= 'Bcc: '.$bcc_email."\r\n";
    }

    return $args;
}

我正在使用“活动日历”,所以我也尝试了这个:

add_action( 'event_tickets_rsvp_tickets_generated', 'tribe_tickets_cc_organizer', 10, 3 );

function tribe_tickets_cc_organizer( $order_id = null, $post_id = null, $attendee_order_status = null ) {
    $to = tribe_get_organizer_email( $post_id, false );
    // bail if there's no valid email for the organizer
    if ( ! is_email( $to ) ) return;
        $event_name        = get_the_title( $post_id );
        $site_name         = get_bloginfo( 'name' );
        $attendee_list_url = admin_url( 'edit.php?post_type=tribe_events&page=tickets-attendees&event_id=' . $post_id ); 
        $content     = '<a href="' . esc_url( $attendee_list_url ) . '" style="color: #000; font-family: sans-serif;">Check the event attendee list</a>';
        $headers     = array( 'Content-type: text/html' );
        $subject     = sprintf( __( 'Your event %1$s has new attendee(s) - %2$s', 'tribe-extension' ), $event_name, $site_name );
        wp_mail( $to, $subject, $content, $headers);
    }

add_action( 'event_ticket_woo_attendee_created', 'tribe_woo_compat_cc', 10, 4 );

function tribe_woo_compat_cc ( $attendee_id, $event_id, $order, $product_id ) {
    tribe_tickets_cc_organizer( null, $event_id );
}

所有主题都无法按预期工作。他们忽略密件抄送并再次发送所有电子邮件,因此管理员和用户会收到双倍的邮件。但是添加的密件抄送邮件没有收到一封邮件。我无法弄清楚,为什么这不起作用。有人出主意吗?

提前致谢。

【问题讨论】:

    标签: wordpress email events woocommerce bcc


    【解决方案1】:

    也许你可以试试:

    function add_bcc_all_emails( $headers, $object ) {
    
        $headers = array( 
             $headers,
             'Bcc: Me <my@mail.net>' ."\r\n",
        );
    
        return $headers;
    }
    add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 2 );
    

    【讨论】:

    • 谢谢,那个对我有用!老实说,我相信问题是在电脑前大约 30 厘米(~11 英寸)。所以我建议我已经发布的 sn-ps 之一应该为其他人工作。
    【解决方案2】:

    对于无代码解决方案,请尝试使用 Post SMTP 插件来处理您的电子邮件。在设置/消息下,所有来自 WP 的电子邮件(包括来自 WooCommerce)都有一个密件抄送选项。

    【讨论】:

      【解决方案3】:

      向所有 WooCommerce 电子邮件发送密件抄送:

      • 从您当前主题的 functions.php 文件中删除之前添加的代码 sn-ps
      • 在您当前主题的functions.php 文件中添加以下sn-p

      add_filter( 'woocommerce_email_headers', 'lh_wc_add_bcc_email', 10, 2 );
      
      function lh_wc_add_bcc_email( $headers, $email ) {
      
          $headers .= 'BCC: Your name <you@email.com>' . "\r\n"; //replace 'Your name' with your name and 'you@email.com' with your email address
      
          return $headers;
      }
      

      或者你可以使用这个插件: CC & BCC for Woocommerce Order Emails

      【讨论】:

      • 感谢sn-p,但这对我根本不起作用。只是收到的普通邮件。
      猜你喜欢
      • 2021-05-17
      • 2020-05-31
      • 1970-01-01
      • 2015-12-19
      • 2011-02-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      相关资源
      最近更新 更多