将WooCommerce取消和失败的订单的管理员电子邮件设置为密件抄送

问题描述 投票:1回答:1

我目前正在使用此代码来发送有关失败和取消的订单的通知。

function wc_cancelled_order_add_customer_email( $recipient, $order )
{ 
 return $recipient . ',' . $order->billing_email; 
} 
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 );

问题是,我在woocommerce设置下在系统中设置的那两个管理员电子邮件也与客户电子邮件一起添加到了电子邮件收件人中。可以对此进行调整,以便管理员电子邮件地址位于BCC上,以便客户看不到其电子邮件地址吗?

php wordpress woocommerce orders email-notifications
1个回答
0
投票

您需要对挂钩函数进行一些小的更改,并添加其他挂钩函数以作为密件抄送收件人处理管理员电子邮件:

add_filter( 'woocommerce_email_recipient_cancelled_order', 'custom_cancelled_and_failed_order_email_recipients', 10, 2 ); 
add_filter( 'woocommerce_email_recipient_failed_order', 'custom_cancelled_and_failed_order_email_recipients', 10, 2 );
function custom_cancelled_and_failed_order_email_recipients( $recipient, $order ) { 
    // Check that the WC_Order object always exist
    if( is_a( $order, 'WC_Order' ) )
        $recipients = $order->get_billing_email(); 

    return $recipients;
} 


add_filter( 'woocommerce_email_headers', 'custom_cancelled_and_failed_order_email_headers', 20, 3 );
function custom_cancelled_and_failed_order_email_headers( $header, $email_id, $order ) {
    // Only for 'cancelled' and 'failed' order notifications
    if( in_array( $email_id, ['cancelled_order', 'failed_order'] ) ) { 
        // Get original admin recipient
        $recipient = WC()->mailer()->get_emails()['WC_Email_Cancelled_Order']->settings['recipient'];
        // Add Admin email As Bcc recipient
        $header .= 'Bcc: ' . $recipient . "\r\n";
    }
    return $header;
}

代码进入您的活动子主题(或活动主题)的functions.php文件中。应该可以。

© www.soinside.com 2019 - 2024. All rights reserved.