Disable the “In Stock” Message on WooCommerce Products
Lets say you have an eCommerce business selling customized coffee mugs. Each mug you sell gets a custom message printed on it and you just fill the orders as they come in. You know each mug gets customized before shipping out, so you don't really need to track the inventory.
If you happen to run out of your local stock of blank mugs then you'll just buy a new box, no big deal. In a case like this you may track inventory, but don't actually need WooCommerce to report this. So how can you hide the 'In Stock' message on your product pages?
How do I hide the “In Stock” message on my product pages?
Some store owners would prefer not to show the “In Stock” message. This can be useful when you sell custom made, or to order, goods that may not be in inventory until an order is place.
Making sure your catalog of products doesn’t display the “In Stock” message is as simple as adding a code snippet to your site’s functions.php file.
<?php
/**
* Hide the "In stock" message on product page.
*
* @param string $html
* @param string $text
* @param WC_Product $product
* @return string
*/
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 );
Keep in mind that you should never make code changes on your production site. You should always test code changes like this in a local, or development, version of your site first. That way if something goes wrong your customers won't see any errors.
Related Articles:
About the Author: Dan Pock
Dan Pock does technical support at Liquid Web with a background in System Administration, Public Relations, and Customer Service. His favorite things include his cats, Oscar Boots, and Dash Nougat; experimenting with PHP; and making up recipes (or at least attempting to). You can find his coding hijinks on GitHub, where he shares most of his projects and open source work.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
What Is WebP and What Makes it Different from Other Image Formats?
Read ArticleTop 10 Password Security Standards
Read ArticleTop 10 Password Security Standards
Read ArticleHow to Install MongoDB on AlmaLinux
Read ArticleHow to Use the WP Toolkit to Secure and Update WordPress
Read Article