Hide products of a category in the “all products” block in a certain page
-
I’m looking for a way to hide products of a specific categories (packs, liquor) on specific pages (Example: Hide packs and liquor in the “wines” page). I don ‘t want to hide them in my entire shop, only in the specified pages.
I searched and another user tried this code and worked for him, but unfortunaly doesnt work on my webpage.
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_page('wines') ) { // set conditions here $tax_query = (array) $q->get( 'tax_query' ); $tax_query[] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'packs, liquor' ), // set product categories here 'operator' => 'NOT IN' ); $q->set( 'tax_query', $tax_query ); } }
What i am doing wrong?
Thanks in advance.
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Hide products of a category in the “all products” block in a certain page’ is closed to new replies.