php - Woocommerce Email attachments not working - file not being attached

I overrided Woocommerce admin-new-email.php with some custom meta, in addition, I have added a filter to add attachment

I overrided Woocommerce admin-new-email.php with some custom meta, in addition, I have added a filter to add attachment file from an ACF options page file field.

function attach_order_notice ( $attachments, $email_id, $order ) {
    // Only for "New Order" email notification (for admin)
    error_log( 'attachments: '. print_r( get_field( 'email_file_attachment', 'options' )['url'], true ) );

    //if( $email_id == 'new_order' ){
        $attachments[] = get_field( 'email_file_attachment', 'options' )['url'];
    //}
    return $attachments;
}
add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );

When I check the log I get a URL to a PDF file and is viewable, when I receive the email there is no file attached, not to admin email nor customer email.

What could be the reason? Thanks

I overrided Woocommerce admin-new-email.php with some custom meta, in addition, I have added a filter to add attachment file from an ACF options page file field.

function attach_order_notice ( $attachments, $email_id, $order ) {
    // Only for "New Order" email notification (for admin)
    error_log( 'attachments: '. print_r( get_field( 'email_file_attachment', 'options' )['url'], true ) );

    //if( $email_id == 'new_order' ){
        $attachments[] = get_field( 'email_file_attachment', 'options' )['url'];
    //}
    return $attachments;
}
add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );

When I check the log I get a URL to a PDF file and is viewable, when I receive the email there is no file attached, not to admin email nor customer email.

What could be the reason? Thanks

Share Improve this question edited Jul 6, 2019 at 10:34 odedta asked Jul 6, 2019 at 10:25 odedtaodedta 961 silver badge16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

Apparently Woocommerce need a local path and not a URL to the file. In order to fix I used this:

function attach_order_notice ( $attachments, $email_id, $order ) {
    // Only for "New Order" email notification (for admin)

    //if( $email_id == 'new_order' ){
        $file_path = wp_upload_dir()['path'];
        $file_name = get_field( 'email_file_attachment', 'options' )['filename'];
        $attachments[] = $file_path . '/' . $file_name;
    //}
    return $attachments;
}
add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );

I hope this helps someone.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745341391a4623342.html

相关推荐

  • php - Woocommerce Email attachments not working - file not being attached

    I overrided Woocommerce admin-new-email.php with some custom meta, in addition, I have added a filter to add attachment

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信