How to Hide Price When Out of Stock In WooCommerce

WooCommerce Hide Price When Out of StockWhen running an online and a physical store, the most challenging task is managing stock availability and inventory. Store owners need to keep track of products customers are interested in, analyze buying behavior, predict consumer demand, and decide on stocking options.

WooCommerce Hide Price When Out of Stock

However, WooCommerce takes care of your inventory needs. WooCommerce is an optimized system that and saves you the time and effort needed to update your stock. Moreover, it is flexible to customization to make up for the features it lacks.

Potential buyers are frustrated when they see the out of stock notification or if the product is unavailable. One of the things you can do is hide the price of products when they are out of stock.

Additionally, there are many situations where this functionality makes sense. For example, if you have a WooCommerce membership store, you probably want to hide your prices from visitors who are not registered.

This guide will show you how to hide the price when the product is out of stock. We will use a custom PHP code to achieve this.

Steps to Hide Price When Out of Stock

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 price when out of stock.
  3. Add the following code to the functions.php file:
/**

 *       Hide Price When Out of Stock

 */

add_filter( 'woocommerce_variable_sale_price_html', 'njengah_remove_prices', 10, 2 );

add_filter( 'woocommerce_variable_price_html', 'njengah_remove_prices', 10, 2 );

add_filter( 'woocommerce_get_price_html', 'njengah_remove_prices', 10, 2 );

function theanand_remove_prices( $price, $product ) {

if ( ! $product->is_in_stock()) {

$price = '';

}

return $price;

}
  1. This is the outcome on the front end:hide out of stock prduct price

Conclusion

In summary, this post shares why it is important to manage inventory in your WooCommerce store. Additionally, I have shared a PHP code snippet that hides the product price when it is out of stock. However, I highly recommend that you have an option to provide interested buyers with a way to be notified when the product is back in stock. If the product is hard to find, you can limit product availability online until you refill your stock. However, if you encounter any problem, please hire a qualified WordPress developer.

Similar Articles

  1. How to Remove Gravatar Storefront Blog WooCommerce