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

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.