Skip to content

Instantly share code, notes, and snippets.

@rashmimalpande
Last active October 10, 2018 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashmimalpande/1211f5892aa9748e45437706ecc398c1 to your computer and use it in GitHub Desktop.
Save rashmimalpande/1211f5892aa9748e45437706ecc398c1 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'woocommerce_coupons_enabled','ts_hide_coupon_field_on_cart' );
function ts_hide_coupon_field_on_cart( $enabled ) {
$product_categories = array('hd', 'led');
$cart = WC()->cart->get_cart();
foreach ( $cart as $id => $cart_item ) {
$_product = wc_get_product($cart_item[ 'data' ]->get_id() );
foreach( $product_categories as $category ) {
if( has_term( $category, 'product_cat', $cart_item[ 'data' ]->get_id() ) ) {
return false;
}
}
}
return $enabled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment