Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conschneider/a4f01f5054cfc41e1b9ca46f548f418d to your computer and use it in GitHub Desktop.
Save conschneider/a4f01f5054cfc41e1b9ca46f548f418d to your computer and use it in GitHub Desktop.
Filter mail recipient of WooCommerce new order mail based on shipping zone.
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 .= ', john@example.com';
} elseif ( $zone_id == 2 ) {
$recipient .= ', jane@example.com';
}
}
return $recipient;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment