For Woocommerce, I want to BCC woocommerce new order/processing order/on-hold order emails to additional multiple email addresses if specific products is purchased.
Current coding I have is able to send to specified emails if specific products purchased.
However, emails are send via 'To:' instead of 'BCC:' And there is 'Reply to' shown which I want it to be remove/hidden as well.
add_filter( 'woocommerce_email_recipient_new_order', 'conditional_recipient_new_email_notification', 15, 2 );
function conditional_recipient_new_email_notification( $recipient, $order ) {
if( is_admin() ) return $recipient; // (Mandatory to avoid backend errors)
// ## — YOUR SETTINGS (below) — ##
$targeted_id = 1111; // HERE define your targeted product ID
$addr_email = '[email protected], [email protected]'; // Here the additional recipient (If multiple, separate them by a coma)
// Loop through orders items
foreach ($order->get_items() as $item_id => $item ) {
if ( $item->get_variation_id() == $targeted_id || $item->get_product_id() == $targeted_id ) {
$recipient .= 'Bcc:' . ', ' . $addr_email . "\r\n";
break; // Found and added – We stop the loop
}
}
$targeted_id2 = 1821; // HERE define your targeted product ID
$addr_email2 = '[email protected], [email protected]'; // Here the additional recipient (If multiple, separate them by a coma)
// Loop through orders items
foreach ($order->get_items() as $item_id => $item ) {
if ( $item->get_variation_id() == $targeted_id2 || $item->get_product_id() == $targeted_id2 ) {
$recipient .= 'Bcc: ' . ', ' . $addr_email2 . "\r\n";
break; // Found and added – We stop the loop
}
}
return $recipient;
}
How can I achieve the outcome I want?
I want BCC: instead of To: And Reply to: to be removed/hidden.