将处理电子邮件通知发送给WooCommerce中的其他隐藏收件人

时间:2020-10-12 11:11:28

标签: php wordpress woocommerce email-notifications bcc

我正尝试使用customer-processing-order.php模板发送额外的邮件,因此,当用户收到包含订单详细信息的邮件时,另一个主题也会收到类似的邮件。

这是我的尝试,但是当我单击“提交订单”按钮时,程序会冻结在加载页面中。

function email_processing_notification( $order_id ) {

    $order = wc_get_order( $order_id );

    // load the mailer class
    $mailer = WC()->mailer();

    $recipient = 'constantmail@gmail.com';
    $subject = __('Some Subject', 'test');
    $content = get_processing_notification_content( $order, $subject, $mailer );
    $headers = "Content-Type: text/html\r\n";

    $mailer->send( $recipient, $subject, $content, $headers );

}

add_action( 'woocommerce_email_order_details', 'email_processing_notification', 10, 1 );


function get_processing_notification_content( $order, $heading = false, $mailer ) {

    $template = 'emails/customer-processing-order.php';

    return wc_get_template_html( $template, array(
        'order'         => $order,
        'email_heading' => $heading,
        'sent_to_admin' => true,
        'plain_text'    => false,
        'email'         => $mailer
    ) );
}

1 个答案:

答案 0 :(得分:2)

您最好使用(用于处理电子邮件通知)将其他电子邮件地址添加为密件抄送

add_filter( 'woocommerce_email_headers', 'custom_cc_email_headers', 10, 3 );
function custom_cc_email_headers( $header, $email_id, $order ) {

    // Only for "Customer Processing Order" email notification
    if( 'customer_processing_order' !== $email_id )
        return $header;

    $email = 'constantmail@gmail.com';

    // Add email address as Cc to headers
    $header .= 'Bcc: '.$email .'\r\n';

    return $header;
}

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

这种方式更加简单,额外的电子邮件地址将对客户隐藏。