WooCommerce: Disable Emails For a Single Order

This is a cool customization that can come useful for WooCommerce store admins, especially when they do manual order status changes via the Orders admin page.

As you know, each order status change triggers an order email (“processing”, “completed”, “on-hold”, etc.), and sometimes the store manager doesn’t want to resend them after each edit.

In this quick tutorial, we will see how to add a checkbox to the single order edit page, so that emails are disabled as long as the checkbox is kept checked. Enjoy!

This cool checkbox will allow you to disable WooCommerce order emails for a single order.

PHP Snippet: Checkbox to Disable Order Emails @ WooCommerce Single Order Edit Page

/**
 * @snippet       Disable Emails for Single Order @ WooCommerce Admin
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_admin_order_data_after_order_details', 'bbloomer_disable_order_emails', 9999 );

function bbloomer_disable_order_emails( $order ) {
	woocommerce_wp_checkbox( array( 
		'id' => '_disable_order_emails', 
		'label' => '<b>Disable Order Emails</b>',
		'description' => 'Check this if you wish to disable emails when order status changes',
		'wrapper_class' => 'form-field-wide',
		'style' => 'width:auto',
	));
}

add_action( 'save_post_shop_order', 'bbloomer_save_disable_order_emails' );
  
function bbloomer_save_disable_order_emails( $order_id ) {
	global $pagenow, $typenow;
	if ( 'post.php' !== $pagenow || 'shop_order' !== $typenow ) return;
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
	if ( isset( $_POST['_disable_order_emails'] ) ) {
		update_post_meta( $order_id, '_disable_order_emails', $_POST['_disable_order_emails'] );
	} else delete_post_meta( $order_id, '_disable_order_emails' );
}

add_filter( 'woocommerce_email_recipient_customer_on_hold_order', 'bbloomer_disable_customer_emails_if_disabled', 9999, 2 );
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'bbloomer_disable_customer_emails_if_disabled', 9999, 2 );
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'bbloomer_disable_customer_emails_if_disabled', 9999, 2 );
// TARGET OTHER EMAILS WITH https://www.businessbloomer.com/woocommerce-add-extra-content-order-email/
  
function bbloomer_disable_customer_emails_if_disabled( $recipient, $order ) {
    $page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
    if ( 'wc-settings' === $page ) {
        return $recipient; 
    }
    if ( get_post_meta( $order->get_id(), '_disable_order_emails', true ) ) $recipient = '';
    return $recipient;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Add Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products. Nothing new so far. But what if […]
  • WooCommerce: Add Content to a Specific Order Email
    Customizing WooCommerce emails via the WordPress dashboard is not easy and – sometimes – not possible. For example, you can’t edit or add content to them unless you’re familiar with code. Well, here’s a quick example to learn how to add content to any WooCommerce default order email. In this case study, our goal is […]
  • WooCommerce: Get Order Info (total, items, etc) From $order Object
    As a WooCommerce development freelancer, every day I repeat many coding operations that make me waste time. One of them is: “How to get ____ if I have the $order variable/object?“. For example, “How can I get the order total“? Or “How can I get the order items“? Or maybe the order dates, customer ID, […]
  • WooCommerce: How to Add a Custom Checkout Field
    Let’s imagine you want to add a custom checkout field (and not an additional billing or shipping field) on the WooCommerce Checkout page. For example, it might be a customer licence number – this has got nothing to do with billing and nothing to do with shipping. Ideally, this custom field could show above the […]
  • WooCommerce Visual Hook Guide: Emails
    WooCommerce customizers: the Visual Hook Guide is back! Here’s a visual HTML hook guide for the WooCommerce Emails. This visual guide belongs to my “Visual Hook Guide Series“, that I’ve put together so that you can find WooCommerce hooks quickly and easily by seeing their actual locations. Let me know in the comments if this […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

2 thoughts on “WooCommerce: Disable Emails For a Single Order

  1. This is a great snippet! Would there be a clean way to reset it after every order save? Because if you forget about it and you do a bulk update via the backend order list the email will also be ignored and you would not know about it.

    1. Or you could add a column to the order list to know if it’s enabled / disabled. Similar example: https://www.businessbloomer.com/woocommerce-add-column-to-orders-table-wp-dashboard/

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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