Ecommerce Shopify WordPress Discussion

Display WooCommerce Product Availability Conditionally

I have both simple and variable products. I noticed that the stock count is displayed on the product page when the product stock is set to manage. How do I set the woocommerce-availability to display only when there are 50 or less products in stock? Something like this perhaps: add_filter( 'woocommerce_get_availability', 'display_availability_conditionally', 10, 2 ); function display_availability_conditionally( $availability, $product ) { if ( $product->managing_stock() && $product->get_stock_quantity() < 50 ) { return $availability; } }
There are some mistakes in your code. Use the following instead: add_filter( 'woocommerce_get_availability_text', 'display_availability_conditionally', 10, 2 ); function display_availability_conditionally( $availability, $product ) { if ( $product->managing_stock() && $product->get_stock_quantity() > 50 ) { $availability = ''; } return $availability; } or the following similar: add_filter( 'woocommerce_get_availability', 'display_availability_conditionally', 10, 2 ); function display_availability_conditionally( $availability, $product ) { if ( $product->managing_stock() && $product->get_stock_quantity() > 50 ) { $availability['availability'] = ''; } return $availability; } Code goes in functions.php file of your child theme (or in a plugin). It should work.

February 4, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.