In Woocommerce I want to edit the "in-stock text", I found multiple answers on the internet, but for some reason, it doesn't work for products that are in stock. It does work for products that are out of stock or are on backorder. I cannot understand what is different and why the in-stock is rendering differently than the other two.
Code:
add_filter( 'woocommerce_get_availability', 'change_in_stock_text', 1, 2);
function change_in_stock_text( $availability, $_product ) {
// product not in stock and not applicable for backorder
if ( ! $_product->is_in_stock() && !$_product->is_on_backorder()) {
$availability['availability'] = __('<i class="far fa-times-circle fa-lg"></i> Niet op voorraad', 'astra');
}
//product not in stock, but backorder is ok -> dropshipping
elseif( $_product->managing_stock() && $_product->is_on_backorder() ){
$availability['availability'] = __('<span style="color: orange;"><i class="far fa-check-circle fa-lg"></i> Op nabestelling</span>', 'astra');
}
//product is in stock (nothing special)
elseif( $_product->is_in_stock()){
$availability['availability'] = __('<i class="far fa-check-circle fa-lg"></i> Op voorraad', 'astra');
}
return $availability;
}
screenshots of the output: https://imgur.com/a/7PWiz62
All help and tips are appreciated!
