mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-04 12:22:24 +08:00
https://stackoverflow.com/questions/78781302/add-attendees-emails-as-cc-for-woocommerce-processing-and-completed-email-notifi
18 lines
847 B
Text
18 lines
847 B
Text
add_filter( 'woocommerce_email_headers', 'additional_cc_recipient', 10, 3 );
|
|
function additional_cc_recipient( $headers, $email_id, $order ) {
|
|
// Only for Processing and Completed order email notifications
|
|
if( in_array($email_id, ['customer_processing_order', 'customer_completed_order']) ) {
|
|
if ( $count = $order->get_meta('cstm_items_count') ) {
|
|
$recipient = []; // initializing
|
|
|
|
for ( $i = 1; $i <= $count; $i++ ) {
|
|
if ( $email = $order->get_meta('cstm_email'.$i) ) {
|
|
// Add attendees emails, avoiding duplicates
|
|
$recipient[$email] = utf8_decode($order->get_meta('cstm_full_name'.$i) . ' <' . $email . '>');
|
|
}
|
|
}
|
|
$headers .= 'Cc: ' . implode(',', $recipient) . "\r\n";
|
|
}
|
|
}
|
|
return $headers;
|
|
}
|