Disclaimer: I’m not a programmer and not very fluent in coding. I just sharing this based on my knowledge and finding.

My client’s site has to manually update the order status because it is not linked to the payment gateway. So, my client has to come out with their own rules. If there is no payment made and receipt received within 24 hours from the order time, the order will be change to cancel. But, in the WooCommerce setting, only the admin will get the email notification on cancel order. So the client won’t know the order has been canceled.

I googled for the solution and I’ve found it at Stackoverflow and at WordPress Support. So for anyone out there who has not much knowledge on WordPress and coding as I am, hope this will help you guys too. This works perfectly for me :).

Firstly install Code Snippets plugin. (WordPress Dashboard>Plugins>Add New and search for Code Snippets).

Then go to the Snippets setting page (WordPress Dashboard>Snippets>Add New). Paste this code:

add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );
function send_custom_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(); // The customer email
    }

    if ( $new_status == 'cancelled' ) {
        // change the recipient of this 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 this 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 );
    } 
}

Save changes and do a test to see if you as the customer received the order cancel notification email.

Thanks for reading and till next time ~

Leave a Reply

Your email address will not be published. Required fields are marked *