How to Hide Quantity In Stock In WooCommerce

WooCommerce Hide Quantity in Stock WooCommerce comes equipped with a decent inventory control capability. You can turn this option in your store using the “Inventory” tab of the Product editing screen in the WordPress admin area.

This tab is very useful, as you can set the amount of a product you currently have in stock. Moreover, you can decide whether to allow an out of stock product to be back-ordered. You can also tell WooCommerce to directly send you an email when a stock amount on an item reaches a certain level.

WooCommerce Hide Quantity in Stock

Once you have checked the “Manage stock?” box on a product, you will see a default setting to add stock messages to each product’s page on your store.

This is very useful when you want to inform potential customers how many of the available items are available. However, there are cases you do not always want to broadcast to the public your inventory levels.product data metabox

If you want to remove the stock messages from your store, you need to make some changes to your WordPress theme or use a plugin.in stock message

Steps to Hide WooCommerce Stock Messages with Code

You can hide stock messages on your products by making code-related changes to the theme you are using for your WooCommerce store. However, since we are making some code changes, I highly recommend that you make a complete backup of your WooCommerce store. This can help you revert to how things were if anything goes wrong with your code changes.

Alternatively, you can use a child theme. A child theme inherits the features of its parent theme but allows you to make modifications safely. It will help you to prevent your changes from being lost. It is important to note that your changes are lost during the next theme update when you edit a parent theme directly.

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to hide WooCommerce stock messages.
  3. Add the following code to the functions.php file:
/**

* Hide the "In stock" message on product page.

*

* @param string $html

* @param string $text

* @param WC_Product $product

* @return string

*/

function njengah_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', 'njengah_wc_hide_in_stock_message', 10, 3 );
  1. To see the outcome, refresh the product page, and you will see that the message has been removed:hide woocommerce stock messages

Conclusion

That is all you need to do to hide the “in stock” message on the product page. If you have used a child theme, this setting will persist no matter what theme updates you do going forward. However, if you are not an experienced WooCommerce user, you can use a plugin so that you will not have to worry about re-editing your theme’s functions.php file.

Similar Articles