add_filter('woocommerce_available_payment_gateways','bbloomer_unset_gateway_by_category'); function bbloomer_unset_gateway_by_category($available_gateways){ global $woocommerce; $category_IDs = array(38,39); foreach ($woocommerce->cart->cart_contents as $key => $values ) { $terms = get_the_terms( $values['product_id'], 'product_cat' ); foreach ($terms as $term) { if(in_array($term->term_id, $category_IDs)){ unset( $available_gateways['cod'] ); break; } break; } } return $available_gateways; }