MainWP Community

Attach a PDF file into order emails in WooCommerce

Attach a PDF file into order emails in WooCommerce on your child site.

Snippet Type

Execute on Child Sites

Snippet

add_filter( 'woocommerce_email_attachments', 'wc_attach_pdf_to_emails', 10, 4 );
 
function wc_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'] . "/2020/09/filename.pdf";
    }
    return $attachments;
}
1 Like