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 badges1 Answer
Reset to default 3Apparently 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
评论列表(0条)