Here’s the quick example to see how to add custom recipients for Woocommerce Emails.
PHP Snippet 1 : Add email recipient to a WooCommerce customer completed order Email
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'codeamend_order_completed_email', 9999, 3 );
function codeamend_order_completed_email( $email_recipient, $email_object, $email ) {
if ( is_admin() ) return $email_recipient;
$email_recipient .= ', your@email.com';
return $email_recipient;
}
PHP Snippet 2: Add Cc / Bcc recipient to a Customer WooCommerce Emails
add_filter( 'woocommerce_email_headers', 'codeamend_email_add_cc_bcc', 9999, 3 );
function codeamend_email_add_cc_bcc( $headers, $email_id, $order ) {
if ( 'customer_completed_order' == $email_id ) {
$headers .= "Cc: Name <your@email.com>\r\n"; // Remove if not needed
$headers .= "Bcc: Name <your@email.com>\r\n"; // Remove if not needed
}
return $headers;
}
PHP Snippet 3: Add Cc / Bcc recipient to a all emails and not just for orders
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'codeamend_email_add_cc_bcc', 10, 2);
function codeamend_email_add_cc_bcc($recipient, $object) {
$recipient = $recipient . ', your@email.com';
return $recipient;
}
To Target Other WooCommerce Order Emails
(Using the same snippet above, you can target different emails by changing the email ID)
if ( $email->id == 'cancelled_order' ) {}
if ( $email->id == 'customer_completed_order' ) {}
if ( $email->id == 'customer_invoice' ) {}
if ( $email->id == 'customer_new_account' ) {}
if ( $email->id == 'customer_note' ) {}
if ( $email->id == 'customer_on_hold_order' ) {}
if ( $email->id == 'customer_refunded_order' ) {}
if ( $email->id == 'customer_reset_password' ) {}
if ( $email->id == 'failed_order' ) {}
if ( $email->id == 'new_order' ) {}
Some More Examples
add_filter( 'woocommerce_email_recipient_cancelled_order', 'codeamend_cancelled_and_failed_order_email_recipients', 10, 2 );
add_filter( 'woocommerce_email_recipient_failed_order', 'codeamend_cancelled_and_failed_order_email_recipients', 10, 2 );
function codeamend_cancelled_and_failed_order_email_recipients( $recipient, $order ) {
// Check that the WC_Order object always exist
if( is_a( $order, 'WC_Order' ) )
$recipients = $order->get_billing_email();
return $recipients;
}
add_filter( 'woocommerce_email_headers', 'codeamend_cancelled_and_failed_order_email_headers', 20, 3 );
function codeamend_cancelled_and_failed_order_email_headers( $header, $email_id, $order ) {
// Only for 'cancelled' and 'failed' order emails
if( in_array( $email_id, ['cancelled_order', 'failed_order'] ) ) {
$recipient = WC()->mailer()->get_emails()['WC_Email_Cancelled_Order']->settings['recipient'];
$header .= 'Bcc: ' . $recipient . "\r\n";
}
return $header;
}
Total Views: 3,269