Randall Jamison
Randall Jamison

Reputation: 329

WooCommerce - send new order email to certain addresses

I need to send the New Order email to certain email addresses depending on various factors in the order - I started with a basic test, and thought the following function would do it, but no such luck (not seeing the CC: on the sent emails). What am I doing wrong?

(yes, I know the following example could be done by just adding the secondary email in the Settings area - this is just a test that I plan to expand on, once I get it working)

add_filter( 'woocommerce_email_headers', 'additional_cc_email_recipient', 10, 3 );
function additional_cc_email_recipient( $headers, $email_id, $order ) {
    if ( $email_id === 'new_order' ){

        $cc_email = "[email protected]";

        $headers .= 'Cc: ' . $cc_email . '\r\n';
    }
    return $headers;
}

Upvotes: 1

Views: 100

Answers (1)

7uc1f3r
7uc1f3r

Reputation: 29670

Try it this way, it works for me

function additional_cc_email_recipient( $header, $email_id, $order ) {
    if ( $email_id == 'new_order' ) {
        // Prepare the the data
        $formatted_email = utf8_decode('My test <[email protected]>');

        // Add Cc to headers
        $header .= 'Cc: '.$formatted_email .'\r\n';
    } else {
        // Prepare the the data
        $formatted_email = utf8_decode('My other test <[email protected]>');

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

    return $header;
}
add_filter( 'woocommerce_email_headers', 'additional_cc_email_recipient', 10, 3 );

Upvotes: 1

Related Questions