I want to sell a .doc file document. when a user have paid, the doc file should be send to his email address and not directly download like it by default does. how can I do that? it will be a downloadable doc file product that will be emailed to their email address
Asked
Active
Viewed 1,884 times
1 Answers
1
Using woocommerce_email_attachments
dedicated hook, you can attach items downloadable files to WooCommerce Customer completed order email notification as follow:
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;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
To make it work on Customer processing order notification, replace:
if( isset( $email_id ) && $email_id === 'customer_completed_order' ){
by:
if( isset( $email_id ) && $email_id === 'customer_processing_order' ){
Related answers:

LoicTheAztec
- 229,944
- 23
- 356
- 399