将pdf附加到仅 woocomerce新订单电子邮件
我正在使用此代码,但是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 ) {
$your_pdf_path = get_template_directory() . '/terms123.pdf';
$attachments[] = $your_pdf_path;
return $attachments;
}
答案 0 :(得分:1)
更新2
在Woocommerce中没有针对客户的“新订单”通知 ...根据启用的付款方式,要定位的通知可以是“客户保留订单”或/和“客户处理订单” < em>(请参阅最后一节)
以下内容将为客户保留订单的电子邮件通知启用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( $email_id, array( 'customer_on_hold_order', 'customer_processing_order' ) ){