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

时间:2018-09-04 17:27:11

标签: php wordpress woocommerce attachment email-notifications

我想排除为客户重设密码和客户新帐户电子邮件添加的电子邮件附件,或者仅限制向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;
}

谢谢

1 个答案:

答案 0 :(得分: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文件中。应该可以。