WooCommerce override left in stock and out of stock text was needed.

In the case of a store that mostly sells unique items placing “1 left in stock” all over the place might not look so good. This was the case for juditmatyus.com .

NOTE: This code may no longer work with the latest version of WooCommerce. Be sure to have backups.

While Woocommerce gives you a few options to play with the word “stock” is always displayed. The main idea here was to get rid of the word “stock” since there is no stock per se, every item is hand made and unique. Once something is sold its gone. Period. There is no stock to refill. There are only a few of each items at any particular time. I was able to change the text to reflect this by doing the following.

1. Change the WooCommerce setting in the dashboard to always show exact number of items.

Go to: WooCommerce > Settings > Products > Inventory and change “Stock display format” to Always show stock e.g. "12 in stock"


2. In your theme’s function.php file add the following

function juditmatyus_availability( $availability, $product ){   
    // Change "x in stock" text to "Only x left"
    $new_availability_text = 'Only ' . str_replace("in stock", "left", $availability['availability']);
    $availability['availability'] = $new_availability_text;

   // Change "out of stock" text to "Sold Out"
    if( $availability['class'] == 'out-of-stock' ){ 
      $availability['availability'] = 'Sold Out';
    return $availability;
add_filter( 'woocommerce_get_availability', 'juditmatyus_availability', 10, 2 );

I hope this helped. Cheers!