Sometime you want to send additional WooCommerce email to certain address or to third party. To send such emails is not quite hard, if you know the right hooks.
We need to hook our function when action is triggered and order is set to cancelled. We use hook woocommerce_order_status_processing_to_cancelled_notification It is triggered when order status changed from processing to cancelled. The hook accepts 1 parameter which is the $order_id. You can use this hook when orders are cancelled in case of some issues occurs e.g Payment Failed.
The WooCommerce mailer class is loaded e.g WC()->mailer(); It has following parameters.
- $recipient: Email address of the person to notify.
- $subject: Subject of your email.
- $content: Content of Email. The ci_get_cancelled_notification_content() functions fetches our email contents.
- $headers: Tells mailer its HTML email.
The wc_get_template_html() is a WooCommerce function that loads email template with contents passed in array.
Add the following code to the functions.php file.