Send an email notification when order status change from pending to cancelled

后端 未结 1 893
后悔当初
后悔当初 2021-01-06 14:18

In previous versions of Woocommerce, an email notification was sent automatically when an order was changed from pending status to cancelled status (In my case, this happens

相关标签:
1条回答
  • 2021-01-06 14:55

    The good new: Using woocommerce_order_status_pending_to_cancelled action hook with a custom function hook in it, solve your problem definitively:

    add_action('woocommerce_order_status_pending_to_cancelled', 'cancelled_send_an_email_notification', 10, 2 );
    function cancelled_send_an_email_notification( $order_id, $order ){
        // Getting all WC_emails objects
        $email_notifications = WC()->mailer()->get_emails();
    
        // Sending the email
        $email_notifications['WC_Email_Cancelled_Order']->trigger( $order_id );
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Tested and perfectly works in WooCommerce 3+ (and 3.1+)

    0 讨论(0)
提交回复
热议问题