A simple, powerful and independent e-commerce platform.
Sell anything with ease.

Exclude products in some categories from the shop

This code removes whole categories from appearing anywhere in the shop. Add the category name to the array in the code.

 * Exclude products in categories from the shop
add_action('woocommerce_product_query', 'cc_exclude_category_from_shop');  

function cc_exclude_category_from_shop($q) {

  $tax_query = (array) $q->get('tax_query');

  $tax_query[] = array(
    'taxonomy' => 'product_cat',
    'field'    => 'slug',
    'terms'    => array('widgets', 'dongles'), // Don't display products in the widgets and dongles categories
    'operator' => 'NOT IN'

  $q->set('tax_query', $tax_query);

View Raw Code ID: 91006