Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce - Unhook/Disable emails
/**
* Code goes in functions.php or a custom plugin.
*/
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_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' ) );
}
@thewaterbearer

This comment has been minimized.

Copy link

thewaterbearer commented Jul 9, 2013

Where does this code exactly go? Thanks

@aprea

This comment has been minimized.

Copy link

aprea commented Jul 10, 2013

/**
* Code goes in functions.php or a custom plugin.
*/
@Drugoy

This comment has been minimized.

Copy link

Drugoy commented Sep 20, 2016

Just a newbie user's review:

I have a webshop that works with only 1 payment type: cash on delivery. So all new orders get their status automatically changed from 'awaiting payment' to 'processing' which generates an email sent to the user.

And I needed to disable all other event hooks (that typically send more emails) except for this one. So I thought that commenting out line 16 would do the job, but it appeared that line 24 also needed to be commented out.

Also, seems like there exist more email-related hooks than the listed ones: woocommerce has more statuses then there are available on the order list page: if you go to a page of a specific order - you'll see 2 drop down lists that represent the order status. I don't know the difference between them, but they seem to have equal meaning yet they do not synchronize.

p.s.: wordpress 4.6.1, woocommerce 2.6.4.

@Drugoy

This comment has been minimized.

Copy link

Drugoy commented Sep 20, 2016

p.p.s.: turns out there are GUI-settings to do the same: the page is located here: /wp-admin/admin.php?page=wc-settings&tab=email

@ahmu83

This comment has been minimized.

Copy link

ahmu83 commented Jul 24, 2017

Thanks for this helpful gist @mikejolley. How to resume those email notifications? i.e:

`if( $pause_emails ) {

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );

} else {

add_action( 'woocommerce_email', 'hook_those_pesky_emails' );

}`

@ahmu83

This comment has been minimized.

Copy link

ahmu83 commented Jul 25, 2017

@jtsternberg

This comment has been minimized.

Copy link

jtsternberg commented Oct 6, 2017

I believe the optimal solution is instead to use the 'woocommerce_email_enabled_' . $this->id filter.

@DavidSteinbauer

This comment has been minimized.

Copy link

DavidSteinbauer commented Oct 24, 2017

If you are using WooCommerce Multilingual you need to remove the WCML hooks (only for admin Emails).

// For WooCommerce Multilingual
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
    global $woocommerce_wpml;
    $class = $woocommerce_wpml->emails;
    remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $class, 'new_order_admin_email' ), 9 );
    remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $class, 'new_order_admin_email' ), 9 );
    remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $class, 'new_order_admin_email' ), 9 );
    remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $class, 'new_order_admin_email' ), 9 );

}
@rajdeeptayde

This comment has been minimized.

Copy link

rajdeeptayde commented Dec 13, 2019

How can i remove the emails going to admin email, I don't want to change the admin email so is there any way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.