php Woocommerce在发送失败/取消订单时向客户发送电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Woocommerce在发送失败/取消订单时向客户发送电子邮件相关的知识,希望对你有一定的参考价值。


// Send email to customer on failed or cancelled order
add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );
function send_custom_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 );
    } 
}

以上是关于php Woocommerce在发送失败/取消订单时向客户发送电子邮件的主要内容,如果未能解决你的问题,请参考以下文章

php 取消订单时自动恢复WooCommerce Stock

php Woocommerce拒绝多个失败订单的结账

过滤 woocommerce 取消未付订单

WooCommerce - 从 functions.php 文件发送新订单/客户发票电子邮件

如何在 WooCommerce 的订单支付页面上检索订单 ID

WooCommerce Google Analytics:发送有关非标准成功页面的订单信息