0

我尝试了几种方法来向 Woocommerce 电子邮件添加其他收件人,但它似乎只适用于主要收件人是管理员的测试订单。

这些是我尝试过的片段。如果订单的客户是管理员,则电子邮件会发送到两个地址。如果订单包含客户电子邮件地址,它只会发送到该电子邮件地址而不是抄送。

以下是我尝试过的代码片段:

add_filter( 'woocommerce_email_recipient_customer_processing_order', 'my_email_recipient_filter_function', 10, 2);

function my_email_recipient_filter_function( $recipient ) {
$recipient = $recipient   . ', secondemail@example.com';
return $recipient;
}

.

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

function woocommerce_email_cc_copy( $headers, $email ) {
if ( $email == 'customer_processing_order') {
    $headers .= 'CC: Your name <secondemail@example.com>' . "\r\n"; //just repeat this line again to insert another email address in BCC
}

return $headers;
}

.

这个有效,但每封电子邮件通知都会触发:

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

function mycustom_headers_filter_function( $headers, $object ) {
        $headers .= 'CC: My name <secondemail@example.com>' . "\r\n";

    return $headers;
}

如果我添加电子邮件$object,那么它只会在客户处理订单时触发,它只会抄送管理员电子邮件(仅抄送,不是收件人),而不是客户(既不是抄送也不是收件人)。

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

function mycustom_headers_filter_function( $headers, $object ) {
 if ( $object == 'customer_processing_order') {
        $headers .= 'CC: My name <secondemail@example.com>' . "\r\n";
 }

    return $headers;
}

我会很感激任何建议。

4

2 回答 2

2

以下代码适用于 Woocommerce 最新版本(v3.4.3)在“CC”中添加自定义电子邮件以用于客户处理电子邮件通知:

add_filter( 'woocommerce_email_headers', 'custom_cc_email_headers', 20, 3 );
function custom_cc_email_headers( $header, $email_id, $order ) {

    // Only for "Customer Completed Order" email notification
    if( 'customer_processing_order' !== $email_id )
        return $header;

    // Prepare the the data
    $formatted_email = utf8_decode('Mister bean <misterbean@example.com>');

    // Add Cc to headers
    $header .= 'Cc: '.$formatted_email .'\r\n';

    return $header;
}

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

您甚至可以将其添加到密件抄送而不是抄送,就像在这个答案线程中一样:
为特定的 Woocommerce 电子邮件通知添加自定义电子邮件到密件抄送


该钩子woocommerce_email_recipient_customer_processing_order似乎在 Woocommerce 3.4.x 中不起作用。

于 2018-06-27T20:49:14.877 回答
0

罪魁祸首是 Woocommerce$email_id订阅customer_processing_ordercustomer_processing_renewal_order. 更新此文本后,标题和收件人都可以修改。

Woocommerce 订阅的标头钩子:

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

function mycustom_headers_filter_function( $headers, $object ) {

// If Woocommerce Subscriptions is active, this needs the renewal email id
 if ( $object == 'customer_processing_renewal_order') {
        $headers .= 'CC: My name <secondemail@example.com>' . "\r\n";
 }

    return $headers;
}

和收件人挂钩:

// If Woocommerce Subscriptions is active, hook needs the renewal email id
add_filter( 'woocommerce_email_recipient_customer_processing_renewal_order', 'my_email_recipient_filter_function', 10, 2);

function my_email_recipient_filter_function( $recipient ) {
$recipient = $recipient   . ', secondemail@example.com';
return $recipient;
}
于 2018-06-30T01:09:06.507 回答