Untitled

 avatar
unknown
plain_text
2 years ago
803 B
2
Indexable
add_action( 'woocommerce_order_status_changed', 'send_cancel_email_notification_to_customer', 10, 4 );

function send_cancel_email_notification_to_customer( $order_id, $old_status, $new_status, $order ) {
    if ( $new_status == 'cancelled' ) {
        $customer_email = $order->get_billing_email();
        $mailer = WC()->mailer();

        // Email heading and subject
        $subject = 'Your Order Has Been Cancelled';
        $email_heading = 'Order Cancelled';

        // Message body with WooCommerce email template
        $message = $mailer->wrap_message( $email_heading, 'Dear Customer, your order #' . $order_id . ' has been cancelled. If you have any questions, please contact us.' );

        // Send the email
        $mailer->send( $customer_email, $subject, $message, '', '' );
    }
}
Editor is loading...
Leave a Comment