最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论