Are you looking for a way to send a custom email on order status change? WooCommerce is packed with many features that allow you to sell anything online. WooCommerce includes core order statuses that define the workflow of your store.
After each status, the shopper is notified via email. For example, when the order goes from “Processing” to “Completed”, the Completed email is sent to the customer.
However, some of them may not fit the workflow of your online store. This is why many store owners use custom order statuses.
It is worth mentioning that if you want to target a transition, for example from “Processing” to “Custom Status”, no email will trigger.
This means that we have to send a custom email.
WooCommerce Send Email on Status Change
In this post, we will show you how to trigger an email for a custom order status. It is important to note that we will be using custom code to achieve this.
Therefore, we recommend creating a child theme before you proceed. This will ensure that your changes are not lost during an update.
Let us look at how you can implement this solution in your store.
Steps to Send Email on Status Change
If it is your first time adding custom code, please take a full backup of your site. This will help you revert to the previous version if you encounter any challenges.
We will be creating a custom email for the “Refused” status:
Here are the steps you need to follow:
- Log into your WordPress site and access the Dashboard as the admin user.
- From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will send a custom email on status change.
- Add the following code to the php file:
/**
* @snippet Send Formatted Email @ WooCommerce Custom Order Status
*/
// Targets custom order status "refused"
// Uses ‘woocommerce_order_status_’ hook
add_action( ‘woocommerce_order_status_refused’, ‘njengah_status_custom_notification’, 20, 2 );
function njengah_status_custom_notification( $order_id, $order ) {
$heading = ‘Order Refused’;
$subject = ‘Order Refused’;
// Get WooCommerce email objects
$mailer = WC()->mailer()->get_emails();
$mailer[‘WC_Email_Customer_Completed_Order’]->heading = $heading;
$mailer[‘WC_Email_Customer_Completed_Order’]->settings[‘heading’] = $heading;
$mailer[‘WC_Email_Customer_Completed_Order’]->subject = $subject;
$mailer[‘WC_Email_Customer_Completed_Order’]->settings[‘subject’] = $subject;
// Send the email with custom heading & subject
$mailer[‘WC_Email_Customer_Completed_Order’]->trigger( $order_id );
// You have to use the email ID chosen above and also that $order->get_status() == "refused"
}
[/php]After adding this code, custom emails will be sent on status change. Remember to use your custom order status name in the code.
Conclusion
By now, you should be able to send custom emails on status change. You can add different sections to the email depending on your needs. If you need further help you can consider getting in touch with me.
Similar Articles
- How to Hide Order Status In WooCommerce
- How Get Product ID on Checkout Page Or Order Page In WooCommerce
- How to Rename Order Status Messages in WooCommerce
- How to Change Checkout Endpoints WooCommerce
- How to Send to Mpesa WooCommerce Payment for Free
- 30+ Best WordPress Mailing List Plugins for List Building
- How to Change WooCommerce Checkout Labels
- How to Change Text in WooCommerce Email
- How to Hide Update Cart Button WooCommerce Cart Page
- How to Hide, Change or Remove WooCommerce On Sale Badge
- How to Hide Customer Order Email For Free Orders WooCommerce
- How to Auto Approve Orders in WooCommerce
- How to Change WooCommerce Email Colors
- How to Get Order ID on Checkout Page WooCommerce
- How to Set Up WooCommerce Checkout Field Placeholder
- How to Create Custom Order Received Page WooCommerce
- How to Change WooCommerce Checkout Page Title
- How to Change Add to Cart Button to Read More WooCommerce
- How to Check if User is Logged In WordPress