I have ‘hide out of stock’ checked in the settings, however when using the layered navigation widget to filter results by shoe size, it is returning products which have that size listed as an attribute, but the size is out of stock. Is there a fix to this?
WordPress version 3.9.1, WooCommerce version 2.1.7
He means not showing the products in the filter results. If a user filters by size M, he wants to see available size M products in the results, not All products that used to have a size M but dont anymore…
This is something woocommerce has not solved in years! and something that anyone opening a woocommerce store should know. I am sure most of them wont use woocommerce because of this issue alone.
I solve it by running the following script every night
The problem this script fixes is: the sidebar filters the product by
attribute
but the stock is manage by product variation (child post).The DB doesn’t have a way to link the 2 fields, therefore it is not possible to create a query that filters attributes that has a matching variation with stock == 0.
Therefore this script solve the problem by deleting products attributes that have stock == 0
here is a opposite script to set an attribute for a product with stock > 0 and a missing attr:
NOTE:
this is not a proper solution to the problem – a solution should be at the design level, i.e. finding a way to link the 2 fields with an SQL query, this solution is a temp by-pass until a real solution is available
I didn’t fully tested this code, I will update the answer if necessary in the future
I’m not fully familiar with the DB structure of wordpress or woocommerce, and the result of this code might change depending on different plugins, using this code is at your own risk
In WooCommerce, the default option is that, it shows all products that are in stock and out of stock on search results and the product category pages. This is a WooCommerce default functionality
Link regarding this:
https://github.com/woothemes/woocommerce/issues/5840
Also, not showing these products on the contrary is a bad idea, as it is not as per the best SEO practices.