WooCommerce is a popular e-commerce plugin for WordPress that allows users to easily sell products and manage inventory. However, the default “Out of stock” label that appears when a product is unavailable can be unappealing for some store owners. Fortunately, it is possible to replace this label with a custom name, such as “Sold”.

Code Snippet to replace “out of stock” with “sold” in woocommerce

add_filter('woocommerce_get_availability', 'availability_filter_func');


function availability_filter_func($availability)


                $availability['availability'] = str_ireplace('Out of stock', 'Sold', $availability['availability']);

                return $availability;


To do this, you will need to add a small piece of code to your website’s functions.php file. The code snippet provided above can be used to replace the “Out of stock” label with the word “Sold”, but you can also replace it with any other word or phrase that you prefer.

First, copy the code snippet provided above and paste it into the functions.php file of your WordPress theme. Make sure to paste it at the end of the file, as it is important that this code is executed after all other functions have been defined.

The code uses the woocommerce_get_availability filter, which is used to change the default availability text of a product. The filter function takes an array of availability information as an argument and returns the modified array.

The filter function replaces the “Out of stock” text with the word “Sold” by using the str_ireplace() function, which performs a case-insensitive search and replace on the availability string.

Once you have added the code to your functions.php file, you should save the file and upload it to your server. After this, the “Out of stock” label on your WooCommerce products should be replaced with the custom name you have chosen, in this case “Sold”.

It’s worth noting that, you could use this filter to change other texts as well, as long as you know the text you want to change and the new text you want to replace it with.

In conclusion, replacing the “Out of stock” label with a custom name in WooCommerce is a simple process that can be achieved by adding a small piece of code to your functions.php file. This can help to improve the appearance of your store and better communicate the availability of your products to customers.