I succesfully added a filter to woocommmerce single product’s short description that displays a different message based on stock quantity and availability. The code is as follows:
add_filter( 'woocommerce_short_description', 'custom_stock_messages', 25 );
function custom_stock_messages($desc) {
global $product;
$prodquantity = $product->get_stock_quantity();
if ( ! $product->is_in_stock() ) {
$desc .= '<p>ãã®ååã¯å®å£²ãã¾ããã</p>';
return $desc;
}
else {
if ( $prodquantity < 1 ) {
$desc .= '<p>ãã®ååã¯ã注æãåãã¦ãã製ä½ã«å
¥ããããçºéã¾ã§10æ¥ï½2é±éé ãã¾ãã</p>';
return $desc;
}
else {
return $desc;
}
}
}
It works like a charm for simple products, but for variable products it only works if the stock is managed at a product level. If I, instead, choose to manage it at a variation level, the messages do not change when selecting the variation. I tried and tried but I can’t figure this out, as I’m still not an expert programmer. Thanks in advance
Alessio