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.
[su_box title=”Note:” style=”glass” box_color=”#3ac6eb” radius=”20″]WordPress Code Warning: This article features code changes, or snippets, that you can make in your active themes function.php file. If you are unfamiliar with this task, or want to brush up, we have an article on Managing code snippets in WooCommerce. The technique provided can be used for both WordPress and WooCommerce sites.[/su_box]
<?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.
Open a chat or ticket with us to speak with one of our knowledgeable Solutions Team or an experienced Hosting Advisors today!
Host your WooCommerce store with Liquid Web
Speed is everything in ecommerce, which is why having powerful hosting is important. Liquid Web’s managed WooCommerce hosting and WordPress hosting offers top-rated speeds, robust security, and simple scalability for your store. Learn more now!
Dan Pock