Created
February 16, 2023 16:10
-
-
Save conschneider/a4f01f5054cfc41e1b9ca46f548f418d to your computer and use it in GitHub Desktop.
Filter mail recipient of WooCommerce new order mail based on shipping zone.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_email_recipient_new_order', 'custom_new_order_recipient', 10, 2 ); | |
function custom_new_order_recipient( $recipient, $order ) { | |
$shipping_zone = WC_Shipping_Zones::get_zone_matching_package( $order->get_shipping_packages() ); | |
if ( $shipping_zone ) { | |
$zone_id = $shipping_zone->get_id(); | |
// You can add more conditions to match specific shipping zones here | |
if ( $zone_id == 1 ) { | |
$recipient .= ', [email protected]'; | |
} elseif ( $zone_id == 2 ) { | |
$recipient .= ', [email protected]'; | |
} | |
} | |
return $recipient; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment