Skip to content

Instantly share code, notes, and snippets.

@justinstern
Last active July 14, 2021 17:22
Show Gist options
  • Save justinstern/e707501abe173a57eb4a to your computer and use it in GitHub Desktop.
Save justinstern/e707501abe173a57eb4a to your computer and use it in GitHub Desktop.
This snippet will disable WooCommerce core emails based on the product category
<?php
// Add the below to the bottom of your theme's functions.php:
add_filter( 'woocommerce_email_enabled_customer_processing_order', 'disable_emails_for_fundraising', 10, 2 );
add_filter( 'woocommerce_email_enabled_customer_completed_order', 'disable_emails_for_fundraising', 10, 2 );
function disable_emails_for_fundraising( $enabled, $order ) {
if ( isset( $order ) && count( $order->get_items() ) > 0 ) {
foreach( $order->get_items() as $item ) {
if ( 'line_item' == $item['type'] ) {
$product = $order->get_product_from_item( $item );
foreach ( array( 'fundraising', 'cat2' ) as $category ) {
if ( has_term( $category, 'product_cat', $product->get_post_data() ) ) {
return false;
}
}
}
}
}
return $enabled;
}
@sdesign75
Copy link

Thanks for this. It works great :-)

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