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
function mycustom_shop_display_stock() {
global $product;
if ( !$product->get_manage_stock() && $product->is_in_stock() ) {
echo '<p class="stock in-stock">In Stock</p>';
}
}
add_action( 'woocommerce_before_add_to_cart_button', 'mycustom_shop_display_stock', 11 );
[1]: https://i.stack.imgur.com/aFnN1.png