Last active
January 18, 2024 17:54
-
-
Save mikejolley/3097073 to your computer and use it in GitHub Desktop.
WooCommerce - Unhook/Disable emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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' ) ); | |
} |
Answer to my question above. https://gist.github.com/ahmu83/e6e8aa2febc1b89f9ecb2deff6e4616b
I believe the optimal solution is instead to use the 'woocommerce_email_enabled_' . $this->id
filter.
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 );
}
How can i remove the emails going to admin email, I don't want to change the admin email so is there any way?
Hi,
I would like to inform you that, I don't want to send customers new order emails.
so could you instruct me on how can I stop sending a new order confirmation email?
[ note: I have disabled new order notification for me but I want of customer end ]
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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' );
}`