[英]Woocommerce - Bcc email only when the admin is recipient OR by Order Status
How to Get email recipient to make an conditional function to add extra bcc email header on email only to admin OR by Order Status? 如何使电子邮件收件人具有条件功能,以便仅在电子邮件上向管理员或按订单状态添加额外的密件抄送电子邮件标头?
add_filter( 'woocommerce_email_headers', 'profit_extra_email', 10, 2);
function profit_extra_email( $headers ) {
$headers .= 'BCC: Vendas Promocional Fitness <eu@site.com>' . "\r\n";
return $headers;
}
This function above work, but bcc email retrieve all emails. 此功能可以正常工作,但密件抄送电子邮件会检索所有电子邮件。 I need retrieve only emails to admin OR by Order Status. 我只需要检索发送给管理员或按订单状态发送的电子邮件。
Help any!! 帮助任何人! :O :O
There are 3 variables passed to the woocommerce_email_headers
filter. 有3个变量传递给woocommerce_email_headers
过滤器。 Since none of them appear to be the $in_admin
variable that is passed to templates, we have to take a different approach. 由于它们似乎都不是传递给模板的$in_admin
变量,因此我们必须采用其他方法。 The second param is $email_id
which is a unique identifier for each email class. 第二个参数是$email_id
,它是每个电子邮件类别的唯一标识符。 Therefore we can make an array of all the admin emails and check if the current email is in that array. 因此,我们可以对所有管理员电子邮件进行排列,并检查当前电子邮件是否在该阵列中。 If so, add your CC. 如果是这样,请添加您的抄送。
function so_31737121_email_headers( $headers, $email_id, $order ){
$admin_emails = array(
'low_stock',
'no_stock',
'backorder',
'cancelled_order',
'new_order'
);
if( in_array( $email_id, $admin_emails ) ){
$headers .= 'BCC: Vendas Promocional Fitness <eu@site.com>' . "\r\n";
}
return $headers;
}
add_action( 'woocommerce_email_headers', 'so_31737121_email_headers', 10, 3 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.