Send cancelled and failed order email to customer in Woocommerce 3

落花浮王杯 提交于 2019-12-04 16:19:25

You should need check that $order argument is valid instance of the WC_Order Class:

add_filter( 'woocommerce_email_recipient_cancelled_order', 'wc_cancelled_order_add_customer_email', 10, 2 );
add_filter( 'woocommerce_email_recipient_failed_order', 'wc_cancelled_order_add_customer_email', 10, 2 );
function wc_cancelled_order_add_customer_email( $recipient, $order ){
    // Avoiding errors in backend (mandatory when using $order argument)
    if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;

    return $recipient .= "," . $order->get_billing_email();
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

You could also use instead in this particular case:

// Avoiding errors in backend (mandatory when using $order argument)
if ( ! method_exists( $order, 'get_billing_email' ) ) return $recipient;

Related and similar:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!