ResolvedOut of stock on variations
Tagged: out of stock, variations, woocommerce
- This topic has 3 replies, 2 voices, and was last updated 2 years, 10 months ago by
Althemist.
- AuthorPosts
- January 13, 2021 at 7:58 pm #28286
escozul
ParticipantHello,
On our eshop, products that are out of stock are getting disabled and should not be available for viewing or ordering anymore.
So we have the woocommerce option “Hide Out of Stock Products” enabled. That works for searches and all. But when you are in a product the variations that are out of stock are still showing. When a customer tries to select one they get a message that the product is not available.
For example check this product: https://www.paramythi.com.gr/product/203800-σετ-φόρμας/ (Don’t mind the greek)
Only size 1 is available. The others are out of stock. So if a user gets into that product he might think that it’s available in all sizes! How do I make it hide the variations options for out of stock variations?
January 15, 2021 at 5:58 pm #28309Althemist
KeymasterHello escozul,
I am afraid there is no way to avoid this and it’s not theme related. Unfortunately, this is how WooCommerce work. If a variation exists it will be shown regardless of it’s stock status. It’d be the same with any WooCommerce theme.
January 15, 2021 at 7:06 pm #28317escozul
ParticipantHello,
Please allow me to disagree.
Indeed Woocommerce does not support that functionality “out of the box” but… you can add that snippet in the functions.php:/** * @snippet Disable out of stock variations @ WooCommerce Single */ add_filter( 'woocommerce_variation_is_active', 'cs_grey_out_variations_out_of_stock', 10, 2 ); function cs_grey_out_variations_out_of_stock( $is_active, $variation ) { if ( ! $variation->is_in_stock() ) return false; return $is_active; }
and that could do the trick. The issue it though that it is not working currently on the theme. It’s possible that you are not using the woocommerce_variation_is_active in your theme?
Just speculation there. Maybe you use that filter for other purposes and negate the effect from the functions.php file. Anyway, since it is doable by using functions.php it is theme related 😉
January 18, 2021 at 3:36 pm #28333Althemist
KeymasterThat could do the trick for simple variations and ONLY if you have up to 5-6 variations. It was tested numerous and times and it doesn’t work correctly with larger number of variations or if you use complex variations consisting of more than one attribute (e.g. color AND size).
It’s discussed numerous times by Rodolfo Melogli (the author of the snippet above). Check the comments bellow: 😉 :
WooCommerce: Disable Out of Stock Variations @ Variable Product Dropdown
We do not modify the default WooCommerce behavior and filters (it’s not allowed on ThemeForest)
- AuthorPosts
You must be logged in and have valid license to reply to this topic.