How to add Email Recipient Add Woo Commerce
If you want to add an email recipient for order notification emails in WooCommerce, you can use the following code:
add_filter( 'woocommerce_email_recipient_new_order', 'add_new_order_email_recipient', 10, 2 );
function add_new_order_email_recipient( $recipient, $order ) {
$recipient .= ', email@example.com'; // Replace "email@example.com" with the email address you want to add
return $recipient;
}
This code adds an email address to the recipient list for the “New Order” notification email in WooCommerce. You can replace “email@example.com” with the email address you want to add. If you want to add multiple email addresses, separate them with a comma.
You can add this code to your theme’s functions.php file or a custom plugin.
By adding an email recipient for order notification emails in WooCommerce, you can ensure that the right people are notified when an order is placed on your site.
add_filter( ‘woocommerce_email_recipient_new_order’, ‘new_order_additional_recipients’, 20, 2 );
function new_order_additional_recipients( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
// Set Below your email adresses
$email1 = 'name1@domain.com';
$email2 = 'name2@domain.com';
// Get the shipping method Id
$shipping_items = $order->get_items('shipping');
$shipping_item = reset($shipping_items);
$shipping_method_id = $shipping_item->get_method_id() . ':';
$shipping_method_id .= $shipping_item->get_instance_id();
// Adding recipients conditionally
if ( 'flat_rate:8' == $shipping_method_id )
$recipient .= ',' . $email1;
elseif ( 'flat_rate:9' == $shipping_method_id )
$recipient .= ',' . $email2;
return $recipient;
}