从Woocommerce中的特定电子邮件通知中排除电子邮件附件

问题描述 投票:1回答:1

我想为客户重置密码和客户新帐户电子邮件排除添加的电子邮件附件,或限制仅向Woocommerce订单电子邮件添加一些附件(并排除发送给管理员的电子邮件的附件)。可能吗?

add_filter( 'woocommerce_email_attachments', 'doc_to_email', 10, 3);
function doc_to_email ( $attachments , $id, $object ) {
    $attachments = array();

    array_push($attachments, get_home_path() . '/doc/Zasady_ochrany_osobnich_udaju.pdf' ); 

    if( !$id == array( 'customer_reset_password', 'customer_new_account') ) {

    array_push($attachments, get_home_path() . '/doc/VOP.pdf' ); 
    array_push($attachments, get_home_path() . '/doc/Reklamacni_rad.pdf' ); 
    array_push($attachments, get_home_path() . '/doc/Reklamacni_protokol.pdf' ); 
    array_push($attachments, get_home_path() . '/doc/Formular_pro_odstoupeni_od_smlouvy.pdf' ); 
    }
    return $attachments;
}

谢谢

php wordpress woocommerce attachment email-notifications
1个回答
1
投票

以下代码将排除所有管理员电子邮件通知中的电子邮件附件以及特定电子邮件通知中的某些附件:

add_filter( 'woocommerce_email_attachments', 'custom_email_attachments', 20, 3 );
function custom_email_attachments ( $attachments = [] , $email_id, $order ) {
    // HERE define customer and admin excluded email Ids
    $excluded_customer_email_ids = array( 'customer_reset_password', 'customer_new_account' );
    $excluded_admin_email_ids = array( 'new_order', 'cancelled_order', 'failed_order' );

    // Excluding attachements from admin email notifications
    if( in_array( $email_id, $excluded_admin_email_ids ) ) 
        return [];

    $file_path = get_home_path() . '/doc/';

    $attachments[] = $file_path . 'Zasady_ochrany_osobnich_udaju.pdf'; 

    // Excluding some customer email notifications
    if( ! in_array( $email_id, $excluded_customer_email_ids ) ) {

        $attachments[] =  $file_path . 'VOP.pdf'; 
        $attachments[] =  $file_path . 'Reklamacni_rad.pdf'; 
        $attachments[] =  $file_path . 'Reklamacni_protokol.pdf'; 
        $attachments[] =  $file_path . 'Formular_pro_odstoupeni_od_smlouvy.pdf'; 

    }

    return $attachments;
}

代码位于活动子主题(或活动主题)的function.php文件中。它应该有效。

© www.soinside.com 2019 - 2024. All rights reserved.