Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hide WooCommerce Product Categories
<?php //<~ dont add me into functions.php
add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' );
/**
* Hide Product Cateories from targetted pages in WooCommerce
* @link https://gist.github.com/stuartduff/bd149e81d80291a16d4d3968e68eb9f8#file-wc-exclude-product-category-from-shop-page-php
*
*/
function prefix_custom_pre_get_posts_query( $q ) {
if( is_shop() || is_page('awards') ) { // set conditions here
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'cat1', 'cat2' ), // set product categories here
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
}
@ismetkaracats

This comment has been minimized.

Copy link

@ismetkaracats ismetkaracats commented Feb 16, 2020

Hello my friend

the code you provided doesn't work

can you check if it works

@davemac

This comment has been minimized.

Copy link

@davemac davemac commented Nov 17, 2020

Can confirm it does indeed work ...

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