Last active
January 22, 2025 21:40
-
-
Save Acephalia/c4406e43c002b9e1f43b16516c786fb2 to your computer and use it in GitHub Desktop.
Woocommerce Disable Order Processing Email For Virtual Products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' ) ); | |
} | |
} | |
} |
Nice! Thank you.
Glad it was useful!
Thanks for this!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Thank you.