Skip to content

Instantly share code, notes, and snippets.

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
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 );

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


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