woocommerce

How to change In Stock or Out of Stock text in WooCommerce

Sharing is caring!

WooCommerce has become one of the popular eCommerce WordPress plugin and just exceeded 1 million downloads few months ago. Anyway, when more and more people are using the plugin, i believe you will come to a point when you need simple customization or tweak that will give you hard time as you are not coder or someone who know PHP.

Today, i would like to share how you actually can change default “In Stock” or “Out of Stock” text at WooCommerce product page. Let’s get started by giving you example:

1. You would like to change “In Stock” to “Available”

2. You would like to change “Out of Stock” to “Sold Out”

Step 1: Open your functions.php file at your current theme folder (wp-content/themes/[THEME]/functions.php) You can download functions.php file from FTP, edit then upload again, OR you cab go to WordPress Admin -> Appearance -> Editor, and click functions.php to edit then save.

Step 2: Put below code to the bottom of the file:

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'] = __('AVAILABLE', 'woocommerce');
 
    //change text "Out of Stock' to 'SOLD OUT'
    if ( !$_product->is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce');
        return $availability;
    }

Final Step: Save the file above and done. You’ve told WooCommerce to get custom status for stock display at single pages. Hope you get some idea on how to tweak WooCommerce by reading more my articles.

62 thoughts on “How to change In Stock or Out of Stock text in WooCommerce”

  1. 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’] = __(‘AVAILABLE’, ‘woocommerce’);

    //change text “Out of Stock’ to ‘SOLD OUT’
    if ( !$_product->is_in_stock() ) $availability[‘availability’] = __(‘SOLD OUT’, ‘woocommerce’);
    return $availability;
    }

    I have put this code in function.php file and its display sold out only single product page when i click the product no badge shown on the archive page.

  2. Thanks, It’s really helpful, after adding filter it got changed from product but its showing in the category over the image, can you please help on to change from over image.

    Thanks in advance.

Leave a Reply to Gary Cancel Reply

Your email address will not be published. Required fields are marked *