Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Last active June 1, 2022 17:20
Show Gist options
  • Save claudiosanches/c250f1c660ccb81fc76b0968d50b514b to your computer and use it in GitHub Desktop.
Save claudiosanches/c250f1c660ccb81fc76b0968d50b514b to your computer and use it in GitHub Desktop.
WooCommerce - Hide the "In stock" message on product page.
<?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 );
@E-VANCE
Copy link

E-VANCE commented Jun 1, 2022

Don't know why, but doesn't work with new wersion of woocomerce. Maybe samoeone find it why?

add_filter( 'woocommerce_get_stock_html', '__return_empty_string', 10, 2 );

works fine with the latest WC, must be something else...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment