如何将所有 Woocommerce 电子邮件发送到其他电子邮件地址?

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

我希望将所有电子邮件发送到另一封电子邮件,以便解析它们(使用 Sendgrid 入站解析)。

这是我目前拥有的:

function custom_add_email_address_to_emails( $headers, $object ) {
    $additional_email = '[email protected]';
    $headers .= 'Cc: ' . $additional_email . "\r\n";
    return $headers;
}

add_filter( 'woocommerce_email_headers', 'custom_add_email_address_to_emails', 10, 2 );
不幸的是,抄送似乎不适用于入站解析,因此我需要实际将电子邮件添加为收件人。你知道我该怎么做吗?

php wordpress email woocommerce hook-woocommerce
1个回答
0
投票
您可以使用复合挂钩将收件人添加到 WooCommerce 预定义电子邮件通知

woocommerce_email_recipient_{$email_id}

在下面的代码中:

    您将在第一个功能中定义所需的电子邮件通知
  1. 您将在第二个功能中定义所需的其他收件人(电子邮件)。
代码:

add_action('woocommerce_init', 'additional_email_recipient_for_notifications'); function additional_email_recipient_for_notifications(){ // HERE below define the desired email notification $email_ids = array( 'new_order', 'customer_on_hold_order', 'customer_processing_order', 'customer_completed_order', ); foreach( $email_ids as $email_id ) { add_filter( "woocommerce_email_recipient_{$email_id}", "additional_email_recipient" ); } } function additional_email_recipient( $recipient ) { // HERE below define your additional email recipients $additional_recipient = array('[email protected]', '[email protected]'); $recipient .= ',' . implode(',', $additional_recipient); return $recipient; }
代码位于子主题的functions.php 文件中(或插件中)。已测试并有效。

相关:

使用 WooCommerce 中的电子邮件 ID 定位特定电子邮件通知

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