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

Hide Specific Product From Shop Page

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.

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

WooCommerce Remove Update Cart Button
Change Price of Specific Product in Cart
Redirect to Checkout after Click on Add to Cart Button

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.

You May Also Like

About the Author: Aman Mehra

Hey! I'm Aman Mehra and I'm a full-stack developer and have 5+ years of experience. I love coding and help to people with this blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version