WooCommerce: “New Order” Email Recipient Based on Billing Country
The amazing thing about WooCommerce is that you can override any setting with a few lines of code. In today’s example we will try to code a solution where the “New Order” WooCommerce email will be delivered to a custom recipient based on the billing country.
This could be helpful when the WooCommerce store is managed by multiple people, and you want to make sure that order notifications only go to the right manager. Enjoy!
PHP Snippet: Change WooCommerce “New Order” Email Recipient Based on Billing Country
/**
* @snippet Switch New Order Email Recipient Based on Billing Country
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 8
* @community https://businessbloomer.com/club/
*/
// PART 1
// Lets define the array of 'country code' => 'email' pairs
function bbloomer_location_admin( $location ) {
$admins = array(
'US' => 'usamanager@test.com',
'CA' => 'canadamanager@test.com',
// etc
);
return $admins[$location];
}
// PART 2
// Lets set the new order email recipient
add_filter( 'woocommerce_email_recipient_new_order', 'bbloomer_dynamic_recipient', 9999, 3 );
function bbloomer_dynamic_recipient( $email_recipient, $order_object, $email ) {
if ( is_admin() ) return $email_recipient;
if ( $order_object && $location = $order_object->get_billing_country() ) {
$email_recipient = bbloomer_location_admin( $location );
}
return $email_recipient;
}
This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101
Related content
WooCommerce: Add Content to a Specific Order Email Customizing WooCommerce emails via the WordPress dashboard is not easy and – sometimes – not possible. For example, you can’t edit or add content to them unless you’re familiar with code. Well, here’s a quick example to learn how to add content to any WooCommerce default order email. In this case study, our goal is […]
WooCommerce: How to Add a Custom Checkout Field Let’s imagine you want to add a custom checkout field (and not an additional billing or shipping field) on the WooCommerce Checkout page. For example, it might be a customer licence number – this has got nothing to do with billing and nothing to do with shipping. Ideally, this custom field could show above the […]
WooCommerce Visual Hook Guide: Emails WooCommerce customizers: the Visual Hook Guide is back! Here’s a visual HTML hook guide for the WooCommerce Emails. This visual guide belongs to my “Visual Hook Guide Series“, that I’ve put together so that you can find WooCommerce hooks quickly and easily by seeing their actual locations. Let me know in the comments if this […]
WooCommerce: Add To: Cc: Bcc: Email Recipients The WooCommerce Email Settings allow you to add custom recipients only for New Order, Cancelled Order, Failed Order and all admin-only emails. But what if you want to add an email recipient to a customer email e.g. the Completed Order one? For example, you need to send it to your dropshipper. Also, you might want […]
WooCommerce: Remove Link to Product @ Order Table There is a slightly annoying thing on the WooCommerce Thank-You Page and WooCommerce emails. Users looking at the order table can actually click on the Products they just purchased and abandon the page before taking the action you want them to take (see image below). So, I coded a simple PHP snippet to remove such […]
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli
2 thoughts on “WooCommerce: “New Order” Email Recipient Based on Billing Country”
Here’s one scenario I’m trying to solve. We sell digital sheet music. Normally very simple: the customer buys and receives the download link to a dynamically created watermarked copy in an email immediately. But one German publisher wants to fulfil the order themselves. So now we’re in an Amazon situation – fulfilled by Amazon or fulfilled by publisher. We need to send a New Order email to the customer saying his order has been taken and will be fulfilled by the publisher (brand taxonomy)and one to the publisher containing the order details. I’m looking at this as adding a Conditional statement to the New Order email, which I also need to amend anyway because we only sell downloads, which would send the New Order to the Publisher as well as the Customer and Admin. Would that be possible?
Rob, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Questions? Feedback? Customization? Leave your comment now! _____
If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!
Here’s one scenario I’m trying to solve. We sell digital sheet music. Normally very simple: the customer buys and receives the download link to a dynamically created watermarked copy in an email immediately. But one German publisher wants to fulfil the order themselves. So now we’re in an Amazon situation – fulfilled by Amazon or fulfilled by publisher. We need to send a New Order email to the customer saying his order has been taken and will be fulfilled by the publisher (brand taxonomy)and one to the publisher containing the order details. I’m looking at this as adding a Conditional statement to the New Order email, which I also need to amend anyway because we only sell downloads, which would send the New Order to the Publisher as well as the Customer and Admin. Would that be possible?
Rob, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!