Hello WooCommerce Customizers!
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!

PHP Snippet: Only Show Products Belonging to One Category @ WooCommerce Shop Page
/**
* @snippet Display Products From 1 Category @ Shop Page
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 6
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
add_action( 'pre_get_posts', 'bbloomer_only_one_category_woocommerce_shop' );
function bbloomer_only_one_category_woocommerce_shop( $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/s
'operator' => 'IN'
)));
}
}
Result: Show Specific Category @ Shop Page
