Skip to content
Advertisement

Display “In Stock” notice for WooCommerce variations with no Managed Stock

I need help for a particular situation. In WooCommerce, if “Manage Stock” is enabled for a simple product or variation, then a notification is being displayed in the product page => such as [this example][1]

However, if “Manage Stock” is not enabled, then there is no notification which I find it a pity because I still want to inform my customers that it’s precisely in stock even if I don’t manage the stock quantities.

I’ve found the below code. For simple products, it works without any problem. However, for variable product, this message is being displayed even before that a variation is selected. This is of course not okay, this code should be displayed only after that a variation is selected.

Can someone help me to fix this? For variable products, this message should only be displayed after that a particular variation is selected.

I’ve made a video capture to be a bit more illustrative : https://sgevcen.tinytake.com/tt/NDQzNTU2OF8xNDAyNTU2NA

JavaScript

Advertisement

Answer

Try the following instead that should allow to display your custom stock availability only for the variations of a variable product (and also on simple products):

JavaScript

Code goes in functions.php file of your active child theme (or active theme). Tested and works.


To exclude some product categories use the following (related to your comment):

JavaScript

Code goes in functions.php file of your active child theme (or active theme). Tested and works.


Related thread: Display custom stock message if “Manage Stock” is not enabled in WooCommerce

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