php - 向 WooCommerce 中的其他隐藏收件人发送处理电子邮件通知
问题描述
我正在尝试使用模板发送额外的邮件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
) );
}
解决方案
您最好使用(用于处理电子邮件通知)将其他电子邮件地址添加为密件抄送:
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 文件中。它应该有效。
这种方式更加简单,并且额外的电子邮件地址将对客户隐藏。
推荐阅读
- c# - Azure C# KeyVaultErrorException:操作返回了无效的状态代码“禁止”
- spring-boot - Spring Boot:为什么在使用多个数据源时未在 createQuery 中扫描实体?
- sql - SQL CONCAT 从表达式中删除零
- python - Python - BeautifulSoup - 抓取的内容仅写入第一个文本文件,而不是后续文件
- python - 使用 Python 多处理共享对象数组
- java - 添加 Pulsar appender 时收到 log4j2 的“No appender found”错误
- javascript - 手动安装 Node js 与使用包管理器
- php - PHP-如何在条件下使用 foreach 求和值?
- android - 当应用程序在模拟器android studio上运行时,热重载无法正常工作
- javascript - 我可以取消选中单选按钮吗?