WooCommerce Stock availability text

In this tutorial I will show you how to change the WooCommerce Stock availability text and explain how it works. You will be able to change the text of “In Stock”, “Only ‘some quantity’ left” & “Out of stock” by following this simple how to guide.

Theme’s Function.php

Copy and Past this code below into your theme’s function (/root/wp-content/themes/YOURTHEME/function.php) file at the bottom, just before the closing ?> sign.

PS. The closing “?> sign is actually telling PHP Server to stop reading the PHP language when you hit that closing tag. So you want to make sure your code is before that tag else it will not be read and WordPress may crash with a error:

The code:

* Change the test for "In Stock / Quantity Left / Out of Stock".

add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
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;

You can ignore the code for now. The areas that you need to focus on is between the round brackets, in-between the ‘single quotes’.

__('Plenty available in our store!', 'woocommerce');

These are called text “strings” in the coding world. You can replace these with your own text and just save the file and refresh you browser. Very important! Don’t remove the single quotes else the code will break and your page will not load.

Change in Stock Text

In stock availability text

As explained above you can just change the following.:


$availability[‘availability’] = __(‘In Stock!‘, ‘woocommerce’);


$availability[‘availability’] = __(‘Whatever you want to say‘, ‘woocommerce’);

Change in Stock Text to only 1 or 2 left

quantity stock availability text

The second part which shows what quantity is left…

if ( $_product->is_in_stock() && $product->get_stock_quantity() <= 2 ) {

…can be adjusted for any other quantity for example.:

if ( $_product->is_in_stock() && $product->get_stock_quantity() <= 4 ) {

Now it will show.: Only 4 left in store! The <= comparison sign shows that it must only show smaller or equal to 4 products left.

The code in this part is also a bit different than the rest. It is because we need to fetch the amount of stock left and place it in the string (text area). You will notice the %s in.: Only %s left in store!

sprintf( __('Only %s left in store!', 'woocommerce'), $product->get_stock_quantity());

This %s is a “place holder” for a variable. In this case we call the variable from the the global object $product.: $product->get_stock_quantity(); This is only for a explanation. If you don’t understand it, don’t worry about it.


$availability[‘availability’] = sprintf( __(‘Only %s left!’, ‘woocommerce’), $product->get_stock_quantity());


$availability[‘availability’] = sprintf( __(‘Only %s left in store!‘, ‘woocommerce’), $product->get_stock_quantity());

Change Out of Stock Text

Nothing fancy here. Just perform the same steps as “Change in Stock text”.


$availability[‘availability’] = __(‘Out of Stock!‘, ‘woocommerce’);


$availability[‘availability’] = __(‘Sorry, All sold out!‘, ‘woocommerce’);

Hope you enjoyed this quick tutorial on how to change the WooCommerce Stock availability text.