Hello WooCommerce Customizers!
Today is episode #9 of my “18 snippets in 18 days” challenge (we have 9 days and 10 snippets to go). Hope your WooCommerce snippet library has been growing steadily in the last few days 🙂
I remind you to share on social media and leave blog comments to support my marathon 🙂
Today we take a look at the WooCommerce Shop page and specifically at how to show only the category you want (and exclude all the others). Some store owners may need this, you never know the weird questions you get asked!

WooCommerce Snippet: Show Specific Category @ Shop Page
/** * @snippet Show Unique Category @ Shop Page * @how-to Get CustomizeWoo.com FREE * @sourcecode https://businessbloomer.com/?p=19928 * @author Rodolfo Melogli * @testedwith WooCommerce 2.5.2 */ add_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); function custom_pre_get_posts_query( $q ) { if ( ! $q->is_main_query() ) return; if ( ! $q->is_post_type_archive() ) return; if ( ! is_admin() && is_shop() ) { $q->set( 'tax_query', array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'black' ), // change 'black' with your cat slug 'operator' => 'IN' ))); } remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); }
End Result: Show Specific Category @ Shop Page
