Home > WooCommerce > How to Hide Specific Products from Shop Page and Search Page in WooCommerce?

How to Hide Specific Products from Shop Page and Search Page in WooCommerce?

In this tutorial, we will learn how to hide specific products from woocommerce shop page with just a simple hook. We will make a hook to get the product’s query then we will customize it and then return it with our customization.

You can also hide products based on any specific condition. Like check products in stock, outstock, or have any attributes, variations, etc. You can make it as per your requirement.

Let’s start with it.

Hide Specific Products From Shop Page

To hide the specific product from the woocommerce shop page, we will use woocommerce_product_query_meta_query filter hook. We will add our own custom query as a meta query in my case. You can do it like you want.

OK. Add the following code in your functions.php file and save it. It will hide the out-of-stock products from your shop page.

Hide Specific Products From Search Page

There is another code hook for the search page. If you also want to hide specific products from the search page then you have to add the following code in your functions.php file.

To hide from the search page we will use pre_get_posts action hook. In this hook, we will first get the meta_query object then we added our own query then again set the meta_query. Same as we did above to add your own custom meta query in the existing query.

See the code below.

These are programmatic ways to hide specific products from the shop page (in my case, we hide the out-of-stock products). But you can make any type of condition with your custom field value that you have built with ACF or your own code. You can compare your value and show the result accordingly.

Additionally, If you want to hide out-of-stock products from woocommerce setting page then check the below image.

Hide out of stock products

You have to visit this path WooCommerce > Settings > Products > Inventory as showing in the image and you will find the checkbox to enable/disable for out-of-stock products.

More WooCommerce Tutorials

Hope you understand the code above, If you still have any questions ask me in the comment section. I’ll respond to you as soon as possible. Let me know if want more tutorial like this another condition, I’ll make it for you.

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment