-
-
Save claudiosanches/c250f1c660ccb81fc76b0968d50b514b to your computer and use it in GitHub Desktop.
<?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 ); |
@skoldin
Does this also remove the "not in stock" as well as the "in stock"? And is there a "low stock" (Or something similar) in WooCommerce also?
Nevermind. This should solve my problem:
add_filter( 'woocommerce_get_stock_html', '__return_empty_string', 10, 2 );
Here is hiding the in stock and also the low threhold stock message. Is there a way to hide just the in stock?
There's always the CSS route:
.stock.in-stock {
display:none;
}
Feels a little wrong, but no real downside that I can think of.
Don't know why, but doesn't work with new wersion of woocomerce. Maybe samoeone find it why?
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...
Otherwise, you can simply remove it from this position using the wonderful filter provided by @skoldin, and then insert your other block wherever you want using this kind of ations, playing with the priority to put it where you want:
This avoids having to update your templates everytime there is a woocommerce update ;-)