I am not very familiar with php, and I am trying to add a class to ‘Low stock’ in the snippet below.
What I am trying to achieve is making the Low Stock orange vis CSS in WooCommerce.
function change_stock_text( $availability, $_product ) {
if ( $_product->is_in_stock() ) {
if ( $_product->get_stock_quantity() < 3 ) {
$qty = $_product->get_stock_quantity();
$availability['availability'] = __( "Low stock", 'woocommerce' );
}
}
return $availability;
}
2
Answers
it’s been sometime since I worked with WooCommerce, so i am not sure if this will do the trick, but you can try:
This might work, otherwise there’s likely a hook for it.
add_filter()
is missing$availability
contains[availability]
&[class]
, you change the text, while you want to add a class$qty
is unused in your code__()
is not necessaryTo add a class to the already existing class with the if condition, use the
woocommerce_get_availability_class
filter hook instead