Woo Downloads Sent via Email Attachement

PHOTO EMBED

Fri Feb 26 2021 06:08:43 GMT+0000 (UTC)

Saved by @wearewebheroes #woocommerce #downloads #email

add_filter( 'woocommerce_email_attachments', 'attach_downloadable_files_to_customer_completed_email', 10, 3 );
function attach_downloadable_files_to_customer_completed_email( $attachments, $email_id, $order ) {
    if( isset( $email_id ) && $email_id === 'customer_completed_order' ){
        // Loop through order items
        foreach( $order->get_items() as $item ) {
            $product = $item->get_product(); // The product Object

            if ( $product->is_downloadable() && ( $downloads = $product->get_downloads() ) ) {
                // Loop through product downloads
                foreach( $downloads as $download ) {
                    $attachments[] = $download->get_file();
                }
            }
        }
    }
    return $attachments;
}
content_copyCOPY

Paste in functions.php of active child theme for Woocommerce stores that sell digital downloads that need to be delivered via email to the client after purchase. The downloads are attached to the order complete email.