This is quite an uncommon WooCommerce requirement, but especially for downloadable products the Completed Order email is such as important one – and customers may end up asking you to resend them all their past order emails.
This is an interesting snippet, as it features important functionalities: getting orders by billing email, looping through the results and re-triggering the Completed Order email whenever a specific admin URL parameter is posted. Enjoy!
A customer requested to get all their Completed Order emails once again in their inbox. Maybe because they contain useful info, downloads, or they need to collect some data all together. Great – use their billing email address in any WordPress dashboard page, append it to the current URL with parameter ‘cust-email’, add the snippet below to your functions.php, and all emails will magically bulk trigger!
PHP Snippet: Trigger All Customer’s Past Order Emails @ WooCommerce Admin
While logged in as administrator and in the WordPress dashboard, add parameter “cust-email” with value = a customer’s billing email, hit enter, and the below snippet will trigger.
Example: https://www.businessbloomer.com/wp-admin/post.php?post=232480&action=edit&[email protected]
/** * @snippet Re-Send All Customer’s Completed Emails * @how-to Get CustomizeWoo.com FREE * @author Rodolfo Melogli * @compatible WooCommerce 7 * @donate $9 https://businessbloomer.com/bloomer-armada/ */ add_action( ‘admin_init’, ‘bbloomer_trigger_customer_order_emails_admin’ ); function bbloomer_trigger_customer_order_emails_admin() { if ( isset( $_REQUEST[‘cust-email’] ) && ! empty( $_REQUEST[‘cust-email’] ) ) { if ( ! current_user_can( ‘manage_woocommerce’ ) ) { wp_die( ‘You do not have permission to bulk edit products’ ); } $email = sanitize_email( $_REQUEST[‘cust-email’] ); if ( is_email( $email ) && email_exists( $email ) ) { global $wpdb; $result = $wpdb->get_col( $wpdb->prepare( “SELECT p.ID FROM {$wpdb->posts} AS p INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id WHERE p.post_status = ‘wc-completed’ AND pm.meta_key = ‘_billing_email’ AND pm.meta_value = %s”, $email )); $result = array_map( ‘absint’, $result ); if ( $result ) { foreach ( $result as $order_id ) { $order = wc_get_order( $order_id ); WC()->mailer()->emails[‘WC_Email_Customer_Completed_Order’]->trigger( $order_id, $order ); } } } } }
Where to add this snippet?
You can place PHP snippets at the bottom of your child theme functions.php file (delete “?>” if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files – if you need more guidance, please take a look at my free video tutorial “Where to Place WooCommerce Customization?”
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance 🙂
Need Help with WooCommerce?
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.