php - 如果购买了特定产品,Woocommerce BCC 向多封电子邮件发送电子邮件通知
问题描述
对于 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;
}
我怎样才能达到我想要的结果?
我想要 BCC: 而不是 To: And Reply to: 被删除/隐藏。
解决方案
我认为您可以通过从相反的方向接近它来做到这一点:挂钩 woocommerce_email_headers 有机会包含密件抄送收件人的地方,检查它是否在您要更改的电子邮件的上下文中运行(使用电子邮件 ID 参数),然后使用您已经必须运行订单项目以决定是否添加密件抄送标头(您现有的收件人代码应该适用于该标头)的逻辑。
我没有考虑删除回复标题,但如果您发现它包含在提供给您的钩子的标题中,您可以搜索它并将其替换为空字符串。
推荐阅读
- javascript - 消息收集器如何处理已处理的消息?| 不和谐.js
- sas - 如何在 SAS 中使用实数/数值作为变量?
- javascript - base64解码不重新调整文本node.js
- mapbox-gl-js - MapboxGL 无法绘制全局大小的圆圈?
- python - (python, beautifulsoup) 当一个 'td' 包含某个字符串时,取整个 tr
- c# - 剃刀页面给我“找不到类型或命名空间名称'IBrowserFile'(您是否缺少 using 指令或程序集引用?)”
- laravel - 为 Vue 使用 2 个不同的刀片根模板,以及 Laravel 8 和 Inertia?
- swiftui - 是否可以将 safeAreaInsets 更改为自定义值?
- c - 在链表中创建多个节点
- c# - 在 .NET Core/.NET 5+ 中使用 TransactionScope 和 SQL 连接池时如何避免 PlatformNotSupportedException