php - 仅将 pdf 附加到 Woocommerce 中的特定电子邮件通知
问题描述
仅将 pdf 附加到woocomerce新订单电子邮件
我正在使用此代码,但 PDF 会附加到 woocommerce 中的每封电子邮件
add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
function attach_terms_conditions_pdf_to_email ( $attachments , $email_id, $email_object ) {
$your_pdf_path = get_template_directory() . '/terms123.pdf';
$attachments[] = $your_pdf_path;
return $attachments;
}
解决方案
更新 2
Woocommerce中没有针对客户的“新订单”通知……根据启用的付款方式,目标通知可以是“客户暂停订单”或/和客户处理订单” (请参阅最后的部分)
以下将为客户保留订单电子邮件通知启用 PDF 附件:
add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3 );
function attach_terms_conditions_pdf_to_email ( $attachments , $email_id, $email_object ) {
// Avoiding errors and problems
if ( ! is_a( $order, 'WC_Order' ) || ! isset( $email_id ) ) {
return $attachments;
}
// Only for "Customer On Hold" email notification (for customer)
if( $email_id === 'customer_on_hold_order' ){
$your_pdf_path = get_template_directory() . '/terms123.pdf';
$attachments[] = $your_pdf_path;
}
return $attachments;
}
代码在您的活动子主题(活动主题)的 function.php 文件中。测试和工作。
根据安装中启用的支付网关,您可以:
1)您可以改用“正在处理”电子邮件,替换此行:
if( $email_id === 'customer_on_hold_order' ){
这样:
if( $email_id === 'customer_processing_order' ){
2)您可以同时使用客户“保留”和“处理中”电子邮件,替换此行:
if( $email_id === 'customer_on_hold_order' ){
这样:
if( in_array( $email_id, array( 'customer_on_hold_order', 'customer_processing_order' ) ){
推荐阅读
- c - 在子线程而不是父线程中调用 MPI 接收速度要慢得多
- node.js - 创建 NodeJS 项目时的 Visual Studio System.ValueTuple 程序集错误
- r - 计算 R 中两个数据帧之间的因子数据
- airflow - 气流触发任务仅基于以前的运行状态
- c# - JSON POST 到 Sharepoint 使用图形状态代码 400
- html - Bootstrap:当您滚动到页面中的某个点时,如何更改顶部菜单(即使用 CSS 从透明更改为不透明)?
- sql - 过滤具有奇怪格式的日期数据集
- r - 用长字符串中特定位置的其他字符替换一个字符,并将更改后的字符串在R中递归地保存为新字符串
- c# - 在材料设计表中仅显示不可为空的行
- hive - date_format() where 子句中带有 <= 或 <= 的意外结果