0
votes

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;
}

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;
}

I would appreciate any advice.

2

2 Answers

2
votes

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;
}

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

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


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

0
votes

The culprit was Woocommerce Subscriptions overriding the $email_id for customer_processing_order with customer_processing_renewal_order. After updating this text, both the headers and recipients were modifiable.

The headers hook, for Woocommerce Subscriptions:

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

    return $headers;
}

And the recipient hook:

// 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   . ', [email protected]';
return $recipient;
}