Remove Product Categories from the Shop Page

In this post we will show you how you can easily products with specific categories from the Woocommerce Shop Page with PHP code. In this example, the first three products on the Shop Page are assigned to the category “remove” and they should be removed.

 

This is how the Shop Page looks like before changing the code:

Remove Product Categories from the Shop Page

 

You can remove the products by adding the following code to your functions.php file:

add_action( 'pre_get_posts', 'arrow_design_remove_categories_shop' );
function arrow_design_remove_categories_shop( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() && ! is_user_logged_in() ) {
$q->set( 'tax_query', array(array('taxonomy' => 'product_cat','field' => 'slug',
// Don’t display products in these categories on the shop page
//'terms' => array( 'remove' ),
'terms' => 'remove',
'operator' => 'NOT IN')));
}
remove_action( 'pre_get_posts', 'arrow_design_remove_categories_shop' );
}

This is how the Shop Page looks like after changing the code:

Remove Product Categories from the Shop Page

Conclusion

We hope this Remove Product Categories from the Shop Page post was helpful and you are now able to remove the unwanted product categories also on your website! You can find more articles here:

 

Read another Woocommerce post : ‘Replace Shop Page Title

 

Arrow Design, based in Dublin, Ireland, provides quality website design services in Dublin and beyond at affordable prices. If you would like help with implementing the above code, or any wordpress website development project, contact us. We love website design and it shows! We provide custom wordpress plugin development, website design training and lots more.

We do it all, so you don’t have to!

Related Posts

Woocommerce Account Page Hook Guide

In this article you will find a visual hook guide for the Woocommerce Account Pages, like the Login/Register page, the Downloads page or the Orders page.

Woocommerce PHP – Product Categories by Product ID

Woocommerce Single Product Page Hook Guide

In this article you will find a visual hook guide for the Woocommerce Single Product Page. This should help you to quickly and easily find the hook positions on the page.

Woocommerce PHP – Product Categories by Product ID

Woocommerce PHP – Product Categories by Product ID

In this tutorial you will learn how to check if a product is assigned to a tag, a category or a custom taxonomy. You can check if a product is is on the shop page, in the cart, in an order & more.

…We do more, so you can do less 🙂

 

Leave a message and we will be straight back to you!

Pin It on Pinterest

Share This