Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add bcc to new order form for woocommerce

How can I add BCC or CC to the woo commerce, new order email?

I think this is the code that is running the new order emails: http://codepad.org/kPTpSIM0 I cant seem to find what I need on Google. Thank you in advance.

I found this but I do not know where it goes:

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

function add_bcc_all_emails($headers, $object) {

$headers = array();
$headers[] = 'Bcc: Name <[email protected]>';
$headers[] = 'Content-Type: text/html';

return $headers;
}
like image 789
LukeD1uk Avatar asked Nov 02 '25 07:11

LukeD1uk


1 Answers

Well it looks like you have already read this answer as that is the recommended code, though I believe it will add the BCC on all emails and not just new orders.

Instead I would suggest the following:

add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 3);

function add_bcc_all_emails( $headers, $email_id, $order ) {

    if( 'new_order' == $email_id ){
        $headers .= "Bcc: Name <[email protected]>" . "\r\n";
    }

    return $headers;
}

As for "where the code goes", it should be made into a plugin. Depending on how easily you would like to be able to disable this code in the future you could write it as a regular plugin (disable from Plugins overview) or as a site-specific snippets plugin (permanent until you delete file via FTP).

like image 152
helgatheviking Avatar answered Nov 04 '25 06:11

helgatheviking