How To Hide The Stock Status in WooCommerce

Do you want to hide the stock status in WooCommerce? This article will guide you through hiding the “In Stock” status on WooCommerce single product pages using a custom code snippet.How To Hide The Stock Status in WooCommerce

WooCommerce has become a cornerstone for e-commerce websites worldwide, offering a flexible and feature-rich platform for selling products online. One of its strengths is its high customization level, which allows store owners to tailor the shopping experience to their brand’s unique needs. A common customization request is the ability to hide the “In Stock” status on product pages.

While displaying stock availability can be beneficial in creating a sense of urgency among customers, certain businesses may prefer a cleaner look for their product pages.

Understanding the Default WooCommerce Behavior

By default, WooCommerce displays an “In Stock” or “Out of Stock” message on product pages based on the item’s inventory status. This feature is designed to inform potential buyers about the product’s product’s availability, enhance transparency, and aid in purchase decisions.

However, not all online stores require this level of detail in their product listings. For stores with ample stock or those operating on a made-to-order basis, displaying stock status can be redundant or detract from the overall shopping experience.

Why Hide The Stock Status WooCommerce?

There are several reasons why a WooCommerce store owner might choose to hide the “In Stock” status:

  • Aesthetic Preferences – Removing unnecessary elements for a minimalist website can help achieve a cleaner and more focused product page.
  • Business Model – Stores that do not face frequent stock shortages or that sell digital products might find the stock status irrelevant.
  • Customer Psychology – Eliminating the stock status can help avoid unnecessary urgency or pressure, leading to a more relaxed shopping experience.

How to Hide The Stock Status WooCommerce

The process involves adding a snippet of PHP code to your website. This code snippet will check the product’s stock status and hide the “In Stock” message for available products. Here’s a step-by-step guide to implementing this customization:

Step 1: Access Your Theme’s Functions.php File

To get started, you need to access the functions.php file of your active WordPress theme. You can do this by using an FTP client to connect to your website’s server or through the File Manager in your hosting control panel. Alternatively, you can access the file directly from your WordPress dashboard by navigating to Appearance > Theme Editor and selecting functions.php from the theme files listed on the right.

Step 2: Insert the Custom Code

Copy the following PHP code snippet and paste it at the end of your theme’s functions.php file:

/* Remove "in stock" text form single products */

function remove_in_stock_text_form_single_products( $html, $text, $product ) {

$availability = $product->get_availability();

if ( isset( $availability['class'] ) && 'in-stock' === $availability['class'] ) {

return '';

}

return $html;

}

add_filter( 'woocommerce_stock_html', 'remove_in_stock_text_form_single_products', 10, 3 );

This code works by hooking into the woocommerce_stock_html filter, which is used by WooCommerce to generate the stock status HTML. When a product is found to be “In Stock,” the function returns an empty string for the stock HTML, effectively hiding the “In Stock” message from the product page.

Step 3: Save Your Changes

After adding the code snippet, save the changes to your functions.php file. It’s important to ensure no syntax errors in the code to avoid any website functionality issues.

Step 4: Test the Changes

Visit your website and navigate to a single product page to confirm that the “In Stock” status is no longer visible. It’s a good practice to test this change with products in various stock statuses to ensure the code functions as expected.

Why Use the Code Snippet

  • If you are new to editing the code on a WordPress site, you may break your site.
  • If you have many changes, code snippets tend to be cumbersome to update since some may require an update with every WooCommerce software update. (If the hooks or filters you are using change, the code snippet may no longer work.)
  • Code snippets may create vulnerability to your website security since they are from different sources (third-party developers).
  • Code snippets are freely available and with no upfront costs.
  • Code snippets can be quick to implement for experienced developers who can customize them further.

What is the Alternative Solution

While code snippets do great work and get the job done quickly, they have some drawbacks, and that's the reason plugins exist.

Plugins are ideally organized code snippets that are scalable, dependable, and professionally written to help you keep your site safe and customize it with ease.

To make your work easier, I have put together my 10+ years of experience into a highly useful WooCommerce product (Whideit) that is geared toward hiding all unwanted elements on your store without wasting time.

  • Using Hideit is easy, and you can simply click a button to immediately disable the Add to Cart button along with the price and several other features you may want to hide from users.
  • I specifically designed it to help with my day-to-day work on client projects. I found it very useful and decided to share it with the WooCommerce community.
  • If you are interested, you can find it here. As one of my blog readers, do not forget to subscribe to my mailing list using the form below so that you can CLAIM your 20% OFF introductory discount for WHIDEIT.
  • I also occasionally send important updates in WooCommerce to help you update or keep your site up and running effectively and safely. You can also reach out if you need any further customization or help with hiding any feature on your WooCommerce store.

Conclusion

Customizing the display of stock status on WooCommerce product pages can significantly enhance your online store’s visual appeal and user experience. By following the steps outlined in this guide, you can easily hide the “In Stock” status, achieving a cleaner, more streamlined look for your product listings.

Remember, while custom code solutions offer powerful flexibility, it’s essential to regularly backup your website. In addition, test changes in a staging environment to prevent any potential disruptions to your live site.

If you are not tech savvy, consider using the WHideIt plugin to help you customize your WooCommerce store. We hope this post helped you hide the stock status in WooCommece.

See Also: How to Remove Price from Cart In WooCommerce