Woocommerce:添加第二个电子邮件地址不起作用,除非收件人是管理员



我已经尝试了几种方法将其他收件人添加到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>' . "rn"; //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>' . "rn";
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>' . "rn";
}
return $headers;
}

我将不胜感激任何建议。

以下代码适用于 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 .'rn';
return $header;
}

代码进入函数.php活动子主题(或活动主题(的文件。经过测试并工作。

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


钩子woocommerce_email_recipient_customer_processing_order似乎在Woocommerce3.4.x中不起作用。

罪魁祸首是Woocommerce订阅覆盖了$email_idcustomer_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>' . "rn";
}
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;
}

相关内容

  • 没有找到相关文章

最新更新