Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'woocommerce_email_recipient_new_order', 'custom_email_recipient_new_order', 10, 2 );
- function custom_email_recipient_new_order( $recipient, $order ) {
- // Get the shipping country
- $country_code = $order->get_shipping_country();
- // Get All Zone IDs
- $zone_ids = array_keys( array('') + WC_Shipping_Zones::get_zones() );
- // Loop through Zone IDs
- foreach ( $zone_ids as $zone_id ) {
- // Get the shipping Zone object
- $shipping_zone = new WC_Shipping_Zone($zone_id);
- // Loop through Zone locations
- foreach ( $shipping_zone->get_zone_locations() as $location ){
- if ( $location->type === 'country' && $location->code === $country_code ) {
- $the_zone_id = $zone_id;
- $the_zone_name = $shipping_zone->get_zone_name(); // (You can use the the zone name too)
- break;
- }
- }
- if($found) break;
- }
- if( $the_zone_id == 0 ) {
- $recipient .= ',' . 'james.collins@gmail.com';
- } elseif( $the_zone_id == 2 ) {
- $recipient .= ',' . 'jean.dubreuil@gmail.com';
- } elseif( $the_zone_id == 3 ) {
- $recipient .= ',' . 'joel.chalamousse@gmail.com';
- } else {
- $recipient .= ',' . 'isabelle.frottin@gmail.com';
- }
- return $recipient;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement