【问题标题】:Woocommerce BCC Email Notifications To Multiple Emails If a Specific Product is Purchased如果购买了特定产品,Woocommerce BCC 向多封电子邮件发送电子邮件通知
【发布时间】:2019-06-16 05:13:20
【问题描述】:

对于 Woocommerce,如果购买了特定产品,我想将 woocommerce 新订单/处理订单/暂停订单电子邮件密送至其他多个电子邮件地址。

如果购买了特定产品,我当前的编码可以发送到指定的电子邮件。

但是,电子邮件是通过“收件人:”而不是“密件抄送:”发送的 并且显示了“回复”,我希望它也被删除/隐藏。

add_filter( 'woocommerce_email_recipient_new_order', 'conditional_recipient_new_email_notification', 15, 2 );

function conditional_recipient_new_email_notification( $recipient, $order ) {

    if( is_admin() ) return $recipient; // (Mandatory to avoid backend errors)

    // ## — YOUR SETTINGS (below) — ##

    $targeted_id = 1111; // HERE define your targeted product ID
    $addr_email = 'additional1@gmail.com, additional2@gmail.com'; // Here the additional recipient (If multiple, separate them by a coma)

    // Loop through orders items
    foreach ($order->get_items() as $item_id => $item ) {
        if ( $item->get_variation_id() == $targeted_id || $item->get_product_id() == $targeted_id ) {
            $recipient .= 'Bcc:' . ', ' . $addr_email . "\r\n";
            break; // Found and added – We stop the loop
        }
    }

   $targeted_id2 = 1821; // HERE define your targeted product ID
    $addr_email2 = 'additional3@gmail.com, additional4@gmail.com'; // Here the additional recipient (If multiple, separate them by a coma)

    // Loop through orders items
    foreach ($order->get_items() as $item_id => $item ) {
        if ( $item->get_variation_id() == $targeted_id2 || $item->get_product_id() == $targeted_id2 ) {
            $recipient .= 'Bcc: ' . ', ' . $addr_email2 . "\r\n";
            break; // Found and added – We stop the loop
        }
    }

    return $recipient;
}

我怎样才能达到我想要的结果?

我想要密件抄送:而不是收件人: 并回复:被删除/隐藏。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    我认为您可以通过从相反的方向接近它来做到这一点:挂钩 woocommerce_email_headers 有机会包含密件抄送收件人的地方,检查它是否在您要更改的电子邮件的上下文中运行(使用电子邮件 ID 参数),然后使用您已经必须运行订单项目的逻辑来决定是否添加密件抄送标头(您现有的收件人代码应该适用于该标头)。

    我没有考虑删除回复标题,但如果您发现它包含在提供给您的钩子的标题中,您可以搜索它并将其替换为空字符串。

    【讨论】:

    • 您好,即使挂上 woocommerce_email_headers 后,我仍然无法解决问题。你能帮我推导编码吗,因为我对编码知之甚少。
    • 对于reply-to header的移除,我已经设法在网上搜索到了,所以现在问题不大了。
    • 抱歉,我在 Stack Overflow 上可能有太多活动部件无法解决。如果您可以通过逐步工作将其分解为更小的问题(例如,测试挂钩是否成功加载、记录每个产品等)并将这些问题作为单独的问题发布,我会在遇到它们时进行查看。
    猜你喜欢
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 2022-12-13
    • 2018-09-19
    • 2016-10-08
    • 1970-01-01
    相关资源
    最近更新 更多