How to Check if WooCommerce Email is Enabled or Disabled?
In this tutorial I am going to show you two ways how you can do it in code.
But of course you can always do it manually this way:

Using is_enabled() Method of a Specific Email Object
I think this method is the most correct one and it works great for both default and custom WooCommerce emails.
$email = WC()->mailer()->emails['EMAIL CLASS NAME HERE'];
if( $email->is_enabled() ) {
// email is enabled, let's do something
}Trigger (send) a specific WooCommerce email if it is enabled and update an option if another email is enabled:
$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' );
}It is not even necessary to create a WC()->mailer() object, because you can use objects of emails themselves like WC_Email_New_Order().
$email = new WC_Email_New_Order();
if( $email->is_enabled() ) {
// do stuff
}List of default WooCommerce email class names
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_OrderWC_Email_Cancelled_OrderWC_Email_Failed_OrderWC_Email_Customer_On_Hold_OrderWC_Email_Customer_Processing_OrderWC_Email_Customer_Completed_OrderWC_Email_Customer_Refunded_OrderWC_Email_Customer_InvoiceWC_Email_Customer_NoteWC_Email_Customer_Reset_PasswordWC_Email_Customer_New_Account
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( 'yes' === $email_options[ 'enabled' ] ) {
// 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§ion=EMAIL ID. Usually emails IDs are the same as email class names.
Actually $email_options contains the following array:
$email_options = get_option( 'woocommerce_{EMAIL ID}_settings' );
print_r( $email_options );
/*
(
[enabled] => yes
[subject] =>
[heading] =>
[email_type] => html
[custom_stuff] => custom_stuff
)
*/
Misha Rudrastyh
Hey guys and welcome to my website. For more than 15 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
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.
Hi,
Sure, I will add it to my ideas list.