This page looks best with JavaScript enabled

Customizing the “In stock” message on product page in WooCommerce

 · ☕ 2 min read · 👽 john hashim

There are so many ways this can be overridden or customized depending on how you’re developing your project and your experience, but this is the simple way to do it if you have experience or not.

copy and paste this code in your child theme or parent theme you’re developing in Functions.php

1
2
3
4
5
6
7
function my_wc_hide_in_stock_message( $html, $product ) {
 if ( $product->is_in_stock() ) {
  return '';
 }
 return $html;
}
add_filter( 'woocommerce_get_stock_html', 'my_wc_hide_in_stock_message', 10, 2 );

This would remove the stock being shown every time wc_get_stock_html gets called. In my case, I wanted to call wc_get_stock_html in another part of the product page, so I had to overwrite the template entirely…

It can be overridden by adding the template here: yourtheme/woocommerce/single-product/add-to-cart/simple.php.

If there’s a better way, let me know!

But let say in case you want to do something amazing like displaying a custom message.. You simply have to add it in the

return ''
tag like this

1
return '<p>My Foo Content!!!</p>';

which would look something like this

1
2
3
4
5
6
7
function my_wc_hide_in_stock_message( $html, $product ) {
 if ( $product->is_in_stock() ) {
  return '<p>My Foo Content!!!</p>';
 }
 return $html;
}
add_filter( 'woocommerce_get_stock_html', 'my_wc_hide_in_stock_message', 10, 2 );

OPTION:

the other simple way to do this without a panic is by using CSS

You can add this under Customize > ADDITIONAL CSS

1
2
3
p.stock.in-stock {
    display: none !important;
}

this will never affect your woo updates

Thanks for your time And Got this info when I was searching online so im sure there are other options that would solve your case !!!

Share on

john hashim
WRITTEN BY
john hashim
Web Developer