How to send email to customer on order cancellation WooCommerce

0
443
how to send email to customer on order cancellation woocommerce

How to send email to customer on order cancellation WooCommerce

 

Add this code in your Theme Functions (functions.php) file

add_action('woocommerce_order_status_changed', 'custom_send_email_notifications', 10, 4 );
function custom_send_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 );
}
}

// Add a recipient in this instance
$wc_emails['WC_Email_failed_Order']->recipient .= ',' . $customer_email;

 

 

how to send email to customer on order cancellation woocommerce

Please see the solution here: solution