Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Last active February 10, 2024 12:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Acephalia/c4406e43c002b9e1f43b16516c786fb2 to your computer and use it in GitHub Desktop.
Save Acephalia/c4406e43c002b9e1f43b16516c786fb2 to your computer and use it in GitHub Desktop.
Woocommerce Disable Order Processing Email For Virtual Products
// Disable Order Processing Email For Virtual Products
add_action( 'woocommerce_checkout_process', 'virtual_products_that_dont_annoy_customers' );
function virtual_products_that_dont_annoy_customers() {
// Check if the cart contains virtual products only
$virtual_products_only = true;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( ! $cart_item['data']->is_virtual() ) {
$virtual_products_only = false;
break;
}
}
// If the cart contains virtual products only, remove email notifications
if ( $virtual_products_only ) {
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
}
}
}
@petertwise
Copy link

Nice! Thank you.

@Acephalia
Copy link
Author

Nice! Thank you.

Glad it was useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment