You can send the downloadble product’s file as attachments when order is marked as completed. Add below snipats in current theme’s functions.php for send purchased downloadable files as attachments in the Order Completed and Invoice emails.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php // Add Downloadable Products to Woocommerce Completed Order & Invoice Emails as Attachments function woocommerce_emails_attach_downloadables($attachments, $status, $order) { if ( ! is_object( $order ) || ! isset( $status ) ) { return $attachments; } if ( empty( $order ) ) { return $attachments; } if ( ! $order->has_downloadable_item() ) { return $attachments; } $allowed_statuses = array( 'customer_invoice', 'customer_completed_order' ); if ( isset( $status ) && in_array( $status, $allowed_statuses ) ) { foreach ( $order->get_items() as $item_id => $item ) { foreach ( $order->get_item_downloads( $item ) as $download ) { $attachments[] = str_replace( content_url(), WP_CONTENT_DIR, $download['file'] ); } } } return $attachments; } add_filter( 'woocommerce_email_attachments', 'woocommerce_emails_attach_downloadables', 10, 3); |
Add below snippet to the end of your theme’s functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
function custom_use_customer_from_address ( $from_email, $obj ) { if ( is_a( $obj, 'WC_Email_New_Order' ) ) { $address_details = $obj->object->get_address( 'billing' ); if ( isset( $address_details['email'] ) && '' != $address_details['email'] ) { $from_email = $address_details['email']; } } return $from_email; } add_filter( 'woocommerce_email_from_address', 'custom_use_customer_from_address', null, 2 ); function custom_use_customer_from_name ( $from_name, $obj ) { if ( is_a( $obj, 'WC_Email_New_Order' ) ) { $address_details = $obj->object->get_address( 'billing' ); if ( isset( $address_details['first_name'] ) && '' != $address_details['first_name'] ) { $from_name = $address_details['first_name']; } if ( isset( $address_details['last_name'] ) && '' != $address_details['last_name'] ) { $from_name .= ' ' . $address_details['last_name']; } } return $from_name; } add_filter( 'woocommerce_email_from_name', 'custom_use_customer_from_name', null, 2 ); |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Tip and tricks, wordpress