在 Woocommerce 中下订单后,将附件添加到管理员电子邮件通知
Add an attachment to admin email-notification once order is placed in Woocommerce
我正在尝试在下新订单后将 PDF 文件发送给商店管理员。 woocommerce_email_attachments
挂钩的问题是电子邮件会同时发送给客户和管理员。
add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );
function attach_order_notice ( $attachments, $id, $object ) {
$pdf_path = get_template_directory() . '/notice.pdf';
$attachments[] = $pdf_path;
return $attachments;
}
目前,客户和管理员都收到了新的订单电子邮件(包括附件),我希望客户和管理员都能收到新的订单电子邮件,但只向管理员发送附件。
这可能吗?
$id
是 WC_Email
ID,您可以使用它来定位特定的电子邮件通知,例如 "New order",在成功下订单时发送给管理员,这样:
add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );
function attach_order_notice ( $attachments, $email_id, $order )
{
// Only for "New Order" email notification (for admin)
if( $email_id == 'new_order' ){
$attachments[] = get_template_directory() . '/notice.pdf';
}
return $attachments;
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
已测试并正常工作
我正在尝试在下新订单后将 PDF 文件发送给商店管理员。 woocommerce_email_attachments
挂钩的问题是电子邮件会同时发送给客户和管理员。
add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );
function attach_order_notice ( $attachments, $id, $object ) {
$pdf_path = get_template_directory() . '/notice.pdf';
$attachments[] = $pdf_path;
return $attachments;
}
目前,客户和管理员都收到了新的订单电子邮件(包括附件),我希望客户和管理员都能收到新的订单电子邮件,但只向管理员发送附件。
这可能吗?
$id
是 WC_Email
ID,您可以使用它来定位特定的电子邮件通知,例如 "New order",在成功下订单时发送给管理员,这样:
add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );
function attach_order_notice ( $attachments, $email_id, $order )
{
// Only for "New Order" email notification (for admin)
if( $email_id == 'new_order' ){
$attachments[] = get_template_directory() . '/notice.pdf';
}
return $attachments;
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
已测试并正常工作