Skip to content
Advertisement

Hide all products with a specific stock status from WooCommerce catalog

I’m using Flatsome template on WordPress and Woocommerce site. I also create custom stock status (example noproduzione, used when a product is not created anymore from manufacturer). But I don’t want to show this products (noproduzione stock status) on my site (only in admin pages).

I’m using this code that I write here (I put it in my functions.php file), but it seems that on flatsome does not works. How to apply it on this template?

JavaScript

To create custom code I used some of codes found on StackOverflow

JavaScript

I added code to show the text of availability, and also to hide the cart button if the product is noproduzione stock status

JavaScript

Last, I also added this code, is useful because order the RELATED PRODUCT by “instock” status, and for me is good because do not show the other custom stock status. But I want to apply this to all of my frontend site.

JavaScript

So, the question is: how to hide this products (noproduzione stock status) on my site (and show only in admin pages)? Noproduzione is different from OUTOFSTOCK!

Advertisement

Answer

You should better use dedicated woocommerce_product_query_meta_query filter hook as follows, to hide, from your store, all products that have a specific stock status (works with custom stock status):

JavaScript

Code goes in functions.php file of the active child theme (or active theme). Tested and works on all versions since WooCommerce 3.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement