I am trying to send an additional email notification to one of our locations for delivery, based off the shipping method ID. I found this answer code, but I am not able to change it in the correct way, to make it work with my shipping methods:
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;
}
This is what I tried to use and for some reason I get no email sent to the recipients based on the method ID. Do I need to add order processing into the code for this to trigger? maybe something like this:
if('customer_processing_order' !=$email_id );
if('flat_rate:8' == $shipping_method_id );
I will be grateful for your help.