How to Stop Sending WooCommerce Emails?

June 26, 2020 3 comments
default placeholder

Want to stop all outgoing emails from your WordPress site?

A member of the WordPress Support Club(Learn WordPress) Facebook group asked how to not send WooCommerce emails if the email address was of a certain format. I looked at a few approaches before deciding on a simple one.

This code allows you to unhook and remove the default WooCommerce emails.

Add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Avoid adding custom code directly to your parent theme’s functions.php file, as this will be wiped entirely when you update the theme.

The skeleton code is very simple. The one function handles all the filter calls. The code checks for a specific email address. The Facebook group member needed to match emails with a specific format – a regular expression test with preg_match() would work for it.

Obviously the code could be changed to check other attributes of the order e.g. if certain items were in the order, or the total was over or under a certain amount.

add_action( 'woocommerce_email', 'ashokkuikel_unhook_woocommerce_emails' );
function ashokkuikel_unhook_woocommerce_emails( $email_class ) {
/**
* Hooks for sending emails during store events
**/
remove_action( 'woocommerce_low_stock_notification', array( $email_class, 'low_stock' ) );
remove_action( 'woocommerce_no_stock_notification', array( $email_class, 'no_stock' ) );
remove_action( 'woocommerce_product_on_backorder_notification', array( $email_class, 'backorder' ) );
// New order emails
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
// Processing order emails
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
// Completed order emails
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
// Note emails
remove_action( 'woocommerce_new_customer_note_notification', array( $email_class->emails['WC_Email_Customer_Note'], 'trigger' ) );
}

Ashok kuikel

Hi, I am Ashok Kuikel, WordPress Developer for WordPress Community. While Cloud Computing Associate and Alibaba MVP and ACA for Cloud Professional.

You can follow me on Social Media, GitHub, and via my Blog Channels.

3 responses to “How to Stop Sending WooCommerce Emails?”

  1. Yeah. that’s what I was exploring for.. thanks. Maddy Baillie Shanda

  2. Su blog es un éxito, muy completo. Ahhh cuando la pasión está ahí, todo es 🙂 Goldarina Bordy Cissiee

  3. Das Lesen Ihres Artikels hat sehr viel Spaß gemacht. Donica Hazel Iridis

Leave a Reply

Your email address will not be published. Required fields are marked *

Articles and Tutorials

We love writing about WordPress and latest plugins tutorials, WooCommerce stats, and much more.