Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Send Email to Customer on Cancelled Order in WooCommerce?

In some online stores, customers are given an option to cancel their orders by adding a cancel button in their My Account page. Sometimes, the store might have to cancel your order too, maybe because of payment issues or other reasons. Either way, it’s important to let customers know when their orders are cancelled.

In this post, we will be sending cancelled or failed order emails to customers. This customization makes sure that your customers are always in the know!

Solution: Send Email to Customer on Cancelled Order in WooCommerce

The below code listens for changes in the order status, specifically for “cancelled” or “failed” orders, and sends the cancelled or failed email notifications to customers accordingly. 

add_action('woocommerce_order_status_changed', 'ts_cancelled_email_notifications', 10, 4 );
function ts_cancelled_email_notifications( $order_id, $old_status, $new_status, $order ){
    if ( $new_status == 'cancelled' || $new_status == 'failed' ){
        $wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects instances
        $customer_email = $order->get_billing_email(); // Get the customer email
    }

    if ( $new_status == 'cancelled' ) {
        // change the recipient of the instance
        $wc_emails['WC_Email_Cancelled_Order']->recipient = $customer_email;
        // Sending the email from this instance
        $wc_emails['WC_Email_Cancelled_Order']->trigger( $order_id );
    } 
    elseif ( $new_status == 'failed' ) {
        // change the recipient of the instance
        $wc_emails['WC_Email_Failed_Order']->recipient = $customer_email;
        // Sending the email from this instance
        $wc_emails['WC_Email_Failed_Order']->trigger( $order_id );
    } 
}

Output

When an order is changed to ‘cancelled’ or ‘failed’ statuses, the corresponding email template for cancelled or failed orders is triggered. Subsequently, the respective email notification will be sent to the customer.

How to Send Email to Customer on Cancelled Order in WooCommerce? - Tyche Softwares


Similarly, you can override WooCommerce default behavior of emails originally intended for the admin to be also sent to customer emails. For instance , checkout this post that will send email for pending payment status to customers in WooCommerce.



Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.