Removing a product category from the Shop page
You may have some products that you don't want to advertise to the entirety of your audience. Maybe they're products that only apply to one gender, or products that are only good for someone of a certain age, or some other niche product that doesn't make sense for your whole audience. If you make sure that the products appearing on the shop page apply to everyone, that will keep your conversion rates high.
How to do it…
To remove a product category from the Shop page, we'll have to modify the query to the database. We can use some of the hooks built into WordPress to modify the query rather than writing an entirely new one, which is a huge time-saver. Let's perform the following steps to remove a product category:
- In your code editor, open up your theme's
functions.php
file or a custom WooCommerce plugin. - At the bottom of the file, add the following code:
add_action( 'pre_get_posts', 'woocommerce_cookbook_pre_get_posts_query...