[Resolved] Display an out of stock badge only if all variations are out of stock
This thread is resolved. Here is a description of the problem and solution.
Problem:
I am finding that when a product is variable and one of the variations is out of stock, it sets the "views_woo_in_stock to false/0 even if another variation still has stock. I would like to only show and Out of Stock badge if ALL of the variations are out of stock.
Solution:
Please try these:
Dashboard-> Toolset-> WooCommerce Views
in section "Products Fields for Parametric Searches", click button "Calculate Now".
It will update all field "views_woo_in_stock" values of product posts.
Relevant Documentation:
This support ticket is created 4 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
I am finding that when a product is variable and one of the variations is out of stock, it sets the "views_woo_in_stock to false/0 even if another variation still has stock. I would like to only show and Out of Stock badge if ALL of the variations are out of stock.
I have tried it in my localhost with a fresh WordPress insallation + Woocommerce plugin + the latest version of Toolset plugins.
The shortcodes you mentioned above works fine:
But there is one thing need to pay attention, the custom field "views_woo_on_sale" is for "on sale" products, so if you don't need it, you can remove it, for example:
I do want to display the on sale badge and that code is working fine.
Regarding the out of stock badge, the code works BUT it displays an out of stock badge if ONLY ONE of the variation is out of stock.
For example:
The book Animal Talk shows the Out of Stock badge. See image: animal-talk-out-of-stock.jpg
The book is out of stock for the Board Book variation. See image animal-talk-board-book.jpg
However, the book IS NOT out of stock for the Hardback variation. See image animal-talk-hardback.jpg
So the result is that customers will think that the Animal Talk book is out of stock because there is an Out of Stock badge on the products page even though only the board book version is out of stock and they can still purchase the Hardback variation/version.
I want the Out of Stock badge to ONLY show up if ALL of the variations are out of stock. Does that make sense?