Currently, on the single product page the in stock text shows up as “# in stock”.
I’d like to alter the code a bit but haven’t found a solution. I wasn’t able to find what exact file that line of code is coming from. price.php seemed to have this
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
But it doesn’t do anything. The class is called “stock” when I inspect element.
I tried this bit of code to add in functions.php:
add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
function custom_get_availability( $availability, $_product ) {
//change text "In Stock' to 'SPECIAL ORDER'
if ( $_product->is_in_stock() ) $availability['availability'] = __('SPOTS LEFT', 'woocommerce');
//change text "Out of Stock' to 'SOLD OUT'
if ( !$_product->is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce');
return $availability;
}
However, I want to be able to alter it a bit. I want to add the stock quantity in front of ‘SPOTS LEFT’ but I don’t know where to place it. It doesn’t seem like php can go inside the (”).
I tried this:
<?php echo $product->get_stock_quantity(); ?>
I want to take it up one more notch and actually have the state the number spots left only if the quantity is less than 6. Else, state sold out. Anything above 5 spots will not show.
I’m not sure what the exact syntax is! Any advice would be great.
This is a slight expansion on SotirisK’s answer, which accounts for changing the message when the manage stock option is not chosen.