# Exclude a Category From the Main Shop Page

> Hides products from one or more categories on the main shop page while they remain available in their own category and by direct link.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, shop, categories
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-exclude-category-from-shop/

## Code

```php
add_action( 'woocommerce_product_query', function ( $query ) {
    $exclude = array( 'wholesale' ); // Category slugs to hide from the shop page.

    if ( ! is_shop() ) {
        return;
    }

    $tax_query   = (array) $query->get( 'tax_query' );
    $tax_query[] = array(
        'taxonomy' => 'product_cat',
        'field'    => 'slug',
        'terms'    => $exclude,
        'operator' => 'NOT IN',
    );

    $query->set( 'tax_query', $tax_query );
} );
```

## Notes

List category slugs in $exclude.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Exclude a Category From the Main Shop Page" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
