How to Hide the In Stock Message From WooCommerce Products
WooCommerce displays a stock availability message on product pages — showing text like “5 in stock” when inventory is managed. While this is useful in some cases, many store owners prefer to hide it. You might not want competitors seeing your stock levels, or you may simply want a cleaner product page layout. In this tutorial, we’ll show you how to hide the “in stock” message while keeping the “out of stock” notice visible. This way, customers still get alerted when a product is unavailable, but they won’t see stock quantities for available items. Before: The Default In Stock Message Here’s what a typical WooCommerce product page looks like with the stock message visible. Notice the “5 in stock” text below the price: Add the Code to Hide the In Stock Message Add the following code to the end of your child theme’s functions.php file. You can access it via Appearance → Editor → Theme Functions: function my_wc_hide_in_stock_message( $html, $text, $product ) { $availability = $product->get_availability(); if ( isset( $availability['class'] ) && 'in-stock' === $availability['class'] ) { return ''; } return $html; } add_filter( 'woocommerce_stock_html', 'my_wc_hide_in_stock_message', 10, 3 ); After: In Stock Message Removed After saving the file and refreshing the product page, the in stock message is gone. The product page looks cleaner without it: How This Code Works The code hooks into the woocommerce_stock_html filter, which controls the HTML output of the stock availability message. The function checks the product’s availability class — if it’s in-stock, it returns an empty string (hiding the message). For any other status (like “out of stock”), it returns the original HTML, keeping those messages visible. This means customers will still see “Out of stock” warnings when a product is unavailable, which is important for a good shopping experience. Only the “X in stock” message is hidden. Conclusion Hiding the WooCommerce in stock message is a clean, one-snippet customization that gives you a tidier product page without sacrificing the important out-of-stock notification. A few lines in functions.php and the stock quantity is gone from the customer’s view. Frequently Asked Questions Q: Will the “out of stock” message still show? Yes. The code specifically targets only the “in-stock” class. Out of stock messages and backorder notices remain visible. Q: Does this hide the stock message on archive/shop pages too? This filter primarily affects the single product page. Most themes don’t display stock messages on archive pages by default. If yours does, this filter should cover it since it targets the stock HTML globally. Q: Can I hide the message with CSS instead? Yes, you could use CSS like .stock.in-stock { display: none; } but the PHP method is cleaner because it prevents the HTML from being generated at all, rather than just hiding it visually. Q: Will this survive WooCommerce updates? Yes, as long as the code is in a child theme’s functions.php. The woocommerce_stock_html filter is a stable WooCommerce API hook. The post How to Hide the In Stock Message From WooCommerce Products appeared first on ThemeLocation.
Take Your Experience to the Next Level
NewDownload our mobile app for a faster and better experience.
Comments
0U
Join the discussion
Sign in to leave a comment