I have a problem when I try to retrieve the available quantity of a product in my view.
This is my code :
function wcs_custom_get_availability( $availability, $_product ) {
global $product;
// Change In Stock Text
if ( $_product->is_in_stock() ) {
$availability['availability'] = __( 'Plenty available in our store!', 'woocommerce');
}
// Change in Stock Text to only 1 or 2 left
if ( $_product->is_in_stock() && $product->get_stock_quantity() <= 2 ) {
$availability['availability'] = sprintf( __('Only %s left in store!', 'woocommerce'), $product->get_stock_quantity() );
}
// Change Out of Stock Text
if ( ! $_product->is_in_stock() ) {
$availability['availability'] = __('Sorry, All sold out!', 'woocommerce');
}
return $availability;
}
The result of the execution is as follows : Only left in store!
I have access to the product variable but the result is null but I would like to retrieve the quantity.