WooCommerce-将新订单电子邮件发送到某些地址

时间:2020-04-21 20:57:22

标签: php wordpress woocommerce hook-woocommerce

我需要根据订单中的各种因素将“新订单”电子邮件发送到某些电子邮件地址-我从进行基本测试开始,以为可以使用以下功能,但运气不佳(看不到CC:发送的电子邮件)。我在做什么错了?

(是的,我知道下面的示例可以通过在“设置”区域中添加辅助电子邮件来完成-这只是我计划在其正常工作时进行的一项扩展测试)

add_filter( 'woocommerce_email_headers', 'additional_cc_email_recipient', 10, 3 );
function additional_cc_email_recipient( $headers, $email_id, $order ) {
    if ( $email_id === 'new_order' ){

        $cc_email = "mytestemail@test.com";

        $headers .= 'Cc: ' . $cc_email . '\r\n';
    }
    return $headers;
}

1 个答案:

答案 0 :(得分:1)

尝试一下,对我有用

function additional_cc_email_recipient( $header, $email_id, $order ) {
    if ( $email_id == 'new_order' ) {
        // Prepare the the data
        $formatted_email = utf8_decode('My test <mytestemail@test.com>');

        // Add Cc to headers
        $header .= 'Cc: '.$formatted_email .'\r\n';
    } else {
        // Prepare the the data
        $formatted_email = utf8_decode('My other test <myothertestemail@test.com>');

        // Add Cc to headers
        $header .= 'Cc: '.$formatted_email .'\r\n';     
    }

    return $header;
}
add_filter( 'woocommerce_email_headers', 'additional_cc_email_recipient', 10, 3 );