简体   繁体   中英

How to add custom email notification in Woocommerce?

As title mentioned, is there any possible way to add email notification just like email to customer on cancelled order. I would like to email to notice on cancelled order due to time limit of pending payment.

Any possible way??

在此输入图像描述

You can use action hook woocommerce_order_status_cancelled , this action is executed when order status is changed to cancelled.

In example:

add_action('woocommerce_order_status_cancelled', function($order_id){
  //send email here
}, 10, 1);

Here is a custom hooked function in woocommerce_email_recipient_cancelled_order filter hook:

add_filter( 'woocommerce_email_recipient_cancelled_order', 'adding_customer_email_recipient_to_cancelled', 10, 2 );
function adding_customer_email_recipient_to_cancelled( $recipient, $order ){
    if( is_admin() ) return $recipient;

    $billing_email = $order->get_billing_email();
    $recipient .= ', ' . $billing_email; 
}

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

This code is tested and works on WooCommerce 3.0+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM