添加第二个电子邮件地址不起作用

添加第二个电子邮件地址不起作用

本文介绍了Woocommerce:添加第二个电子邮件地址不起作用,除非收件人是管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have tried several methods to add additional recipients to Woocommerce emails, but it only seems to work on test orders where the primary recipient is the admin.

这些是我尝试过的片段.如果订单的客户是管理员,则将同时发送两个地址的电子邮件.如果订单包含客户电子邮件地址,则仅发送至该电子邮件地址,而不发送至抄送.

These are the snippets I've tried. If the customer for the order is the admin, the email is sent both addresses. If the order contains a customer email address, it is only send to that email address and not the CC.

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

Here are the code snippets I've tried:

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

function my_email_recipient_filter_function( $recipient ) {
$recipient = $recipient   . ', [email protected]';
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 <[email protected]>' . "\r\n"; //just repeat this line again to insert another email address in BCC
}

return $headers;
}

.

此方法有效,但每一封电子邮件通知均会触发:

This one works, but fires with every single email notification:

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

function mycustom_headers_filter_function( $headers, $object ) {
        $headers .= 'CC: My name <[email protected]>' . "\r\n";

    return $headers;
}

如果我在其中添加电子邮件$object,则仅针对客户处理订单触发,仅在管理电子邮件中抄送(仅抄送,不包括收件人),而不是客户(抄送或收件人).

If I add the email $object in, so it only fires for customer processing orders, it only cc's on the admin emails (cc only, not recipient), not customers (neither cc nor recipient).

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 <[email protected]>' . "\r\n";
 }

    return $headers;
}

我将不胜感激.

推荐答案

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

The following code works in Woocommerce last version (v3.4.3) adding a custom email in "CC" for Customer processing email notification:

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 <[email protected]>');

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

    return $header;
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试和工作.

Code goes in function.php file of your active child theme (or active theme). Tested and work.

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

You can even add it to Bcc instead of Cc, like in this answer thread:
Adding custom emails to BCC for specific Woocommerce email notifications

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

The hook woocommerce_email_recipient_customer_processing_order doesn't seem to work in Woocommerce 3.4.x.

这篇关于Woocommerce:添加第二个电子邮件地址不起作用,除非收件人是管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 08:54