繁体   English   中英

将PDF附加到Woocommerce中仅特定的电子邮件通知

[英]Attach pdf to only specific email notification in Woocommerce

安装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;
 }

更新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' ) ){

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM