Basically, in woocommerce you have the option to input multiple email addresses (separated by commas) of who to send the completed order to, in WooCommerce -> Settings -> Emails -> New order. But I need a way to send to only one of these recipients based on the zip code of the customer who is ordering the product. Or completely overwrite woocommerce’s way of handling this.
How can I tie into the function responsible for this, in order to send to the correct recipient? Basically, is there a hook defined for this, or does a plugin exist for something like this, or will I have to edit core WooCommerce files? If edits are needed to core files, can someone point me in the right direction as to which files will need edits?
I had a bit of trouble with helgatheviking’s answer above and also a slightly different use case.
My problems/needs were:
public function get_recipient()
inside of class-wc-email.php expected a string but was getting an array.Here’s what I did instead:
woocommerce_email_recipient_new_order
explode()
andarray_push()
with string concatenation$email .= ',' . $additional_email;
.if( $order->get_payment_method() == "cod" )
.Full example:
Each email has a filter that allows you to adjust the recipients of that email. The filter name is essentially
woocommerce_email_recipient_{$email_id}
.So the following would filter the “to” addresses for the “new_order” email.
I’m not 100% certain on the conditional logic, but I think that should check the shipping zip code and subsequently send to the additional email address.