I found this posted as a comment on another thread but I don't know what I'm supposed to do with it:
if($product->get_stock_quantity() <10){echo 'Limited supply left';}
I figured it should have a hook. I tried woocommerce_after_single_variation but it didn't work
Using woocommerce_get_availability_text
filter hook with the following:
add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2 );
function filter_product_availability_text( $availability_text, $product ) {
if( $product->is_in_stock() && $product->managing_stock() &&
! $product-> is_on_backorder( 1 ) && $product->get_stock_quantity() < 10 ) {
$availability_text .= ' ' . __("(limited supply left)", "woocommerce");
}
return $availability_text;
}
Code goes in function.php file of your active child theme (active theme). Tested and works.