WooCommerce Disable Emails Generator
Turn off specific WooCommerce emails in code, or stop all mail on a staging site, without touching the settings a client can change back.
<?php
/**
* WooCommerce emails, turned off.
*/
add_filter( 'woocommerce_email_enabled_cancelled_order', '__return_false' );
add_filter( 'woocommerce_email_enabled_customer_note', '__return_false' );
Output is valid and updates as you type.
Fix the highlighted fields to update the output.
Turn off the WooCommerce emails you do not want, or stop a staging copy emailing real customers, without relying on a settings checkbox anyone can tick back on.
How to use
- For a live store, turn off specific emails. Filtering
enabledis the light touch; removing the class takes the email out of the settings screen entirely. - For a copy of a live store, use staging mode. It blocks every email the site sends, not only WooCommerce’s, which is what matters when the copy has real orders in it.
- Guard staging mode with a constant defined only on the copy. That constant is the entire safety mechanism, so it belongs in
wp-config.php, never in the database. - Leave the admin exception on if you still want to receive test mail on staging.
- Keep the logging on while you are working. It proves an email would have gone, which is hard to demonstrate otherwise.
Example
Staging mode, the version that matters:
function acme_block_mail( $args ) {
if ( ! defined( 'ACME_STAGING' ) || ! ACME_STAGING ) {
return $args;
}
// No recipients means wp_mail() returns early without sending.
$args['to'] = array();
return $args;
}
add_filter( 'wp_mail', 'acme_block_mail' );
Emptying the recipient list is more reliable than trying to intercept every sender: anything that goes through wp_mail() is covered, including plugins you have not thought about.
Pitfalls
- A staging copy made from a live database has real customer addresses in it. Restocking, bulk status changes and test refunds all send mail. This is the single most damaging WooCommerce mistake there is.
- Turning off
customer_reset_passwordmeans customers cannot recover their accounts, and the failure is silent from their side. woocommerce_email_enabled_<id>leaves the email visible in the settings screen with its checkbox on, which confuses whoever looks after the store next.- Removing the class removes the settings too, including any subject or template overrides stored against it.
- Blocking
wp_mail()does not stop a plugin that talks to an SMTP API directly. SendGrid, Postmark and Mailgun plugins usually route throughwp_mail(), but transactional integrations sometimes do not. - Some hosts and SMTP plugins short circuit
wp_mail()themselves, at a priority that can run before your filter. - Order emails are sent during checkout. A fatal in this filter takes the order confirmation down with it.
- The admin exception matches the
admin_emailoption exactly. A staging copy usually still has the live address in it.
Compatibility
woocommerce_email_classes and woocommerce_email_enabled_<id> have been stable since WooCommerce 2.x and still apply in WooCommerce 8 and 9. The wp_mail filter, which receives and can rewrite the whole argument array, needs WordPress 5.5 or later; before that only wp_mail_from and friends existed. The generated code targets PHP 7.0 and up, and the tool runs entirely in your browser.
Frequently asked questions
How do I stop a staging site emailing customers?
Filter enabled or remove the class?
Does this block WordPress’s own emails?
Will my SMTP plugin still send?
wp_mail(), no. A direct API integration may bypass the filter entirely, so test before trusting it.