Send Automatic Email on Cancelled Orders in WooCommerce
Learn how to automatically notify customers when their order is cancelled in
WooCommerce. With a simple PHP snippet, you can trigger a branded
cancellation email whenever an order changes status to cancelled.
What this snippet does
By default, WooCommerce does not always notify the customer when an order is cancelled. This can create confusion, especially if the customer is not sure whether their payment or order was processed correctly.
With the snippet below, every time an order changes to Cancelled, a customer note is added automatically and WooCommerce sends it to the customer using the default Customer Note email template.
1) Why send a cancellation email in WooCommerce?
When a customer’s order is cancelled without notification, they may:
- Wonder if their payment was processed correctly.
- Contact your support team for clarification.
- Feel less confident about shopping with you again.
By automatically sending a cancellation confirmation email, you can:
- Keep your customers informed.
- Reduce support tickets.
- Improve the overall shopping experience.
2) The WooCommerce cancellation email snippet
Here is a simple PHP snippet you can add to your child theme’s
functions.php file or, preferably, to a custom plugin.
// Automatically notify customer when an order is cancelled (uses Customer Note email)
add_action('woocommerce_order_status_cancelled', function( $order_id ){
$order = wc_get_order( $order_id );
if ( ! $order ) {
return;
}
$msg = 'Your order #' . $order->get_order_number() . ' has been cancelled. '
. 'If this was a mistake or you need assistance, please contact us.';
// true => sends the note to the customer via the default WooCommerce email template
$order->add_order_note( $msg, true );
});
3) How this snippet works
The snippet hooks into the WooCommerce action
woocommerce_order_status_cancelled.
wc_get_order( $order_id ).
$order->add_order_note( $msg, true ), WooCommerce emails the note to the customer.
4) Where to add the snippet
You can add the code using one of the following methods:
- Inside your child theme’s functions.php file.
- Inside a custom plugin, so it is not tied to the active theme.
- Inside a snippets management plugin, if you already use one.
5) Customize the email message
The message sent to the customer is stored in the $msg variable.
You can change it to match your brand tone and customer communication style.
$msg = 'Your order #' . $order->get_order_number() . ' has been cancelled. '
. 'If this was a mistake or you need assistance, please contact us.';
6) Test before going live
Before deploying the snippet to production, always test it on a staging site.
- Add the snippet to your staging site.
- Create a test WooCommerce order using a real recipient email address.
- Change the order status to Cancelled.
- Check that a customer note appears inside the order.
- Confirm that the customer receives the email.
- Check the spam/junk folder and SMTP logs if the email does not arrive.
7) Best practices
- Always test on a staging site before deploying to production.
- Customize the cancellation message to match your brand tone.
- Consider translating the email for multilingual stores.
- Use a child theme or custom plugin to prevent losing changes after theme updates.
- Use an SMTP plugin for more reliable transactional email delivery.
8) Frequently Asked Questions
Yes. Every time an order changes to cancelled, the snippet adds a customer note and asks WooCommerce to send it to the customer.
Yes. You only need to edit the content of the $msg variable inside the snippet.
Check that WooCommerce emails are enabled, that the Customer Note email is active, and that your site sends transactional emails correctly through SMTP.
You can, but a child theme or custom plugin is safer, because the code will not be lost after parent theme updates.
9) Support
For any issue or question related to WooCommerce snippets, you can contact technical support.