• Skip to main content
  • Skip to primary sidebar

Supplemental Resources

Just The Tech, News, and Info We Deem To Post

  • Home
  • Home
  • Home
  • Home
  • Home
  • Home
  • Home
  • Home
  • Home
  • About
  • About
  • About
  • About
  • About
  • About
  • About
  • About
  • About
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • WordPress
  • Marketing
  • Business
  • Computing
  • Security
  • Publicity
  • Resources
  • WHATEVS

Prevent product category from displaying on WooCommerce shop page

Woocommerce Code Snippets

Add the following code to your theme’s function.php file, or a functionality plugin to modify the WooCommerce Shop Page in order to prevent specific categories from displaying on the WooCommerce Shop Page.

<?php

/** WooCommerce Hide Cat. */
/** This code should be added to functions.php of your theme or functionality plugin.  **/
/** DO NOT INCLUDE THE OPENING <?PHP **/

function custom_pre_get_posts_query( $q ) {
    $tax_query = (array) $q->get( 'tax_query' );
    
    $tax_query[] = array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => array( 'your category' ), 
            // Hide products from "your category" on the shop page.
           'operator' => 'NOT IN'
    );

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

}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

by Jack Alltrade on October 16, 2020

Filed Under: Code Snippets Tagged With: Code, Customization, Shop Page, WooCommerce

Reader Interactions

Share Your Two Cents Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

© Copyright Jack Alltrade & Associates 2026 · Purely Supplemental™ is a trademark of Jack Alltrade & Associates