Learn in this tutorial how to send the WooCommerce “new order” email to different recipients, depending on the product purchased, using code.
If you are using WooCommerce, you already know that when a purchase is made, a “new order” email is sent to the account you have indicated in the plugin settings.
But what if, depending on the product purchased, you want the email to be sent to different accounts?
No problem, because you can use a WooCommerce filter to manage it. This can be very interesting for stores that have different departments.
Here’s how to do it:
Snippet to send the “new order” message to another email depending on the purchased product
Add the following code at the end of functions.php or in your functionality plugin:
In this case, you use the
woocommerce_email_recipient_new_order filter and a conditional to set that when the product belongs to the “software” category it should send the new order email to the “firstname.lastname@example.org” email account.
If instead of just sending the email to “email@example.com” you also want it to go to the default email, then substitute:
In this way a copy will be sent to the default email address you have configured, plus the new address you specify.
Of course, you can customize both the category and the email address where you want notifications of new orders to be sent.
As you can see, with a few lines of code you can control to which addresses to send WooCommerce new order emails depending on the purchased product.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉