Attach files to WooCommerce emails

How to attach a file to a WooCommerce order email.

I went searching online as I had to include an pdf document into the order email. I found what I needed at the Business Bloomer web site.
I uploaded a PDF file to the media library of the web site. Then added the title of the PDF file named: Angreskjema.pdf into the code snippet.
As can be seen below.

This is the code I added as a code snippet.

/**
 * @snippet       File Attachment @ WooCommerce Emails
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */
 
add_filter( 'woocommerce_email_attachments', 'bbloomer_attach_pdf_to_emails', 10, 4 );
 
function bbloomer_attach_pdf_to_emails( $attachments, $email_id, $order, $email ) {
    $email_ids = array( 'new_order', 'customer_processing_order' );
    if ( in_array ( $email_id, $email_ids ) ) {
        $upload_dir = wp_upload_dir();
        $attachments[] = $upload_dir['basedir'] . "/Angreskjema.pdf";
    }
    return $attachments;
}

This is the result when ordering with a Hotmail or Outlook email.

Attach file to WooCommerce order email
Attach file to WooCommerce order email.

How to attach multiple files

/**
 * @snippet       Multiple File Attachments @ WooCommerce Emails
 * @how-to        https://easywebdesigntutorials.com/attach-files-to-woocommerce-emails/
 * @author        Easy Web Design Tutorials
 * @inspiredby    Business Bloomer
 * @testedwith    WooCommerce 9
 */
 
add_filter( 'woocommerce_email_attachments', 'ewdt_attach_multiple_pdfs_to_emails', 10, 4 );
 
function ewdt_attach_multiple_pdfs_to_emails( $attachments, $email_id, $order, $email ) {
    
    // Select which emails should include the attachments
    $email_ids = array( 'new_order', 'customer_processing_order' );

    if ( in_array( $email_id, $email_ids ) ) {

        $upload_dir = wp_upload_dir();

        // List of files to attach (absolute paths)
        $files = array(
            $upload_dir['basedir'] . '/2025/07/Angreskjema.pdf',
            $upload_dir['basedir'] . '/2025/07/Produktinfo.pdf',
            $upload_dir['basedir'] . '/2025/07/Garanti.pdf',
        );

        // Add files only if they exist
        foreach ( $files as $file ) {
            if ( file_exists( $file ) ) {
                $attachments[] = $file;
            }
        }
    }

    return $attachments;
}

Please test the code and give me feedback. Thank you.

Another approach

I made the following WooCommerce Github repo issue: https://github.com/woocommerce/woocommerce/issues/54659#event-17336846826

Cory replied in relation to a WooCommerce default solution using templates.
“Ot’s possible to override any email template from within the WP Admin UI. (WooCommerce > Settings > Emails, click on the desired email, and scroll down to the bottom of the screen for the HTML Template section). With a custom template you would be able to add a link to the downloadable file.”
Template structure & Overriding templates via a theme.

Various Resources

https://www.businessbloomer.com/woocommerce-attach-file-pdf-emails/

https://webroomtech.com/add-an-attachment-in-woocommerce-emails/

https://www.damiencarbery.com/2021/05/attach-files-to-woocommerce-order-email

https://woocrmconnector.com/how-to-add-custom-attachments-to-woocommerce-emails-easily/

https://github.com/woocommerce/woocommerce/issues/54659

Angre skjema lenker / In Norway one can change ones mind in relation to purchases made.
One would fill out out a specific form and include it in the package and or email.

https://lovdata.no/dokument/NL/lov/2014-06-20-27/KAPITTEL_6#KAPITTEL_6

https://www.forbrukertilsynet.no/lov-og-rett/angrerettloven

https://skjema-no.com/angrerettskjema/

https://webforumet.no/forum/threads/angrerettskjema-i-woocommerce.19960/page-3

https://webforumet.no/forum/threads/angrerettskjema-i-woocommerce.19960/page-3

Share the article:

2 Comments

Leave a Reply to arnoCancel Reply

Your email address will not be published. Required fields are marked *