Menu Close

WooCommerce: Show Only 1 Category @ Shop Page

default

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!

WooCommerce: Removing All Categories But One From the Shop Page
WooCommerce: Removing All Categories But One From the Shop Page

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

Here's the Before/After picture :)
Here’s the Before/After picture 🙂
View Source
Posted in WooCommerce Tips