How to Check if a WooCommerce Email is Enabled or Disabled?

In this tutorial I will show you two methods that allow you to check anywhere in the code if a certain WooCommerce email is enabled or not. The code will work for both default and custom emails.

#WooCommerce  /    /   2

WooCommerce enabled Customer Note email
Of course you can find it out in WooCommerce > Settings > Emails, but now I want to show you how to do it in the code.

Method 1. get_option() – for custom emails #

Please keep in mind, that this method works for custom emails only. So, if you try to use it for "Customer note" email for example, nothing happens 🙅‍♂️

Anyway, the familiar way is to use get_option( $key ). But what should be in the $key parameter? Please don’t open your code inspector in browser – HTML name attribute is not what you need.

$email_options = get_option('woocommerce_{EMAIL ID}_settings');
if( $email_options['enabled'] == 'yes' ) {
	// do something
}

Where to get email IDs? Easy – if you open email settings page and look at the URL, you will see admin.php?page=wc-settings&tab=email&section=EMAIL ID. Usually emails IDs are the same as email class names.

Actually $email_options contains the following array:

(
	[enabled] => yes
	[subject] => 
	[heading] => 
	[email_type] => html
	[custom_stuff] => custom_stuff
)

Method 2. is_enabled() #

This method works great for both default and custom WooCommerce emails.

$email = WC()->mailer()->emails['EMAIL CLASS NAME HERE'];
 
if( $email->is_enabled() ) {
	// do something
}

By the way you can initialize WC()->mailer() just once and do many cool stuff without creating new object, example $mailer = WC()->mailer().

Example – check if .. email is enabled and if yes, send it, and if another email is enabled, update some option.

$mailer = WC()->mailer();
 
if( $mailer->emails['WC_Email_New_Order']->is_enabled() ) {
	$mailer->emails['WC_Email_New_Order']->trigger( $order_id );
}
 
if( $mailer->emails['WC_Email_Customer_New_Account']->is_enabled() ) {
	update_option( 'jhjkhkhk', 'yes' );
}

And one more example – you can do the same using an object:

$email = new WC_Email_New_Order();
if( $email->is_enabled() ) {
	// do stuff
}

Class Names of the Default WooCommerce Emails #

I think after all of that I just have to give the list of class names of WooCommerce default emails! And here they are:

  • WC_Email_New_Order
  • WC_Email_Cancelled_Order
  • WC_Email_Failed_Order
  • WC_Email_Customer_On_Hold_Order
  • WC_Email_Customer_Processing_Order
  • WC_Email_Customer_Completed_Order
  • WC_Email_Customer_Refunded_Order
  • WC_Email_Customer_Invoice
  • WC_Email_Customer_Note
  • WC_Email_Customer_Reset_Password
  • WC_Email_Customer_New_Account
Misha Rudrastyh
About the author Misha Rudrastyh

Passionate about WordPress and snowboarding, creating websites for over 10 years! Let's work together — just contact me.

If you are a developer too, subscribe to my facebook page.

Comments 2

  • hi,Misha Rudrastyh

    first of all thanks for this nice tutorial

    Can you please make tutorial on how to add custom order status in woocommerce and trigger email when order status change to custom order status ?

    Thanks in advance.

Comments are closed.
If you need my personal help, please contact me. Contact me