# Attach a PDF to Order Completed Emails

> Attaches a file, such as your terms and conditions, a user guide or a returns form, to the WooCommerce "Order completed" email.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Requires: WooCommerce
- Tags: email, woocommerce, attachments, pdf
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-woo-attach-terms/

## Code

```php
add_filter( 'woocommerce_email_attachments', function ( $attachments, $email_id ) {
    $attachment_id = 0;  // Media Library attachment ID.
    $file_path     = ''; // Or an absolute path on the server.
    $email_ids     = array( 'customer_completed_order' ); // Emails that get the file.

    if ( ! in_array( $email_id, $email_ids, true ) ) {
        return $attachments;
    }

    $path = $attachment_id ? get_attached_file( $attachment_id ) : $file_path;

    if ( $path && is_readable( $path ) ) {
        $attachments[] = $path;
    }

    return $attachments;
}, 10, 2 );
```

## Notes

Upload the PDF to the Media Library and set $attachment_id, or set $file_path to an absolute server path.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Attach a PDF to Order Completed Emails" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
