Posted on

WooCommerce: Disable Customer Order Email for Free Orders

There are times when you sell free products to give customers access to a membership, an online course, or for other reasons. In this cases, you might not want to send them the “Order Completed” email, as the follow-up work is done by your email marketing software or they are automatically redirected to the resource upon checkout.

Of course, you definitely want to keep the “Order Completed” emails for orders that are not $0. Unfortunately, the method suggested by WooCommerce which “unhooks the emails” cannot be used together with a conditional check (in our case we need to verify if the Order total is $0), so a workaround is needed. Here’s the fix.

WooCommerce: disable a customer email if the order total is 0

PHP Snippet: Disable Customer Order Email for Free Orders – WooCommerce

 

/**
 * @snippet       Disable Customer Order Email for Free Orders - WooCommerce
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @source        https://businessbloomer.com/?p=74122
 * @author        Rodolfo Melogli
 * @compatible    Woo 3.3.5
 */

// Note: here we are targeting the _completed_ email
// To target another email you can change the filter to e.g.:
// "woocommerce_email_recipient_customer_processing_order"

add_filter( 'woocommerce_email_recipient_customer_completed_order', 'bbloomer_disable_customer_order_email_if_free', 10, 2 );

// Here comes the WooCommerce "hack"...
// If Total = 0 we change the email recipient to ""

function bbloomer_disable_customer_order_email_if_free( $recipient, $order ) {
    if ( $order->get_total() === '0.00' ) $recipient = '';
    return $recipient;
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance ๐Ÿ™‚

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares ๐Ÿ™‚ Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

8 thoughts on “WooCommerce: Disable Customer Order Email for Free Orders

  1. I have a question about a somewhat related topic. Because I couldn’t find anything more related on your site I decided to post my question here. Hope that’s OK?

    WooCommerce order numbers are not sequential. I know there is a SkyVerge plugin that takes care of that, but could you provide us with a snippet to fix this?

    1. Hey Steven, that plugin is probably faster than trying to code it ๐Ÿ™‚ Sorry!

  2. Thanks Rodolfo. It works like a charm.
    Is there any simple solution to display just a single line of text instead of the entire WooCommerce table? I have only one (free) product and don’t want to show the default complex Woo table (with Product, Quantity, Price, VAT and such).

    1. Nick, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  3. What about showing the price as FREE instead of “0”? I have downloadable products so I still need the email to go out but it would be great if it can show FREE instead of “0”.

  4. Thank you, this is just what I was looking for. I can disable a couple of plugins now and improve the full load page perfomance ๐Ÿ˜‰

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.