How to Change Out of Stock Text in WooCommerce
How to Change Out of Stock Text in WooCommerce

Default out of stock notifications do not encourage your customers to remain on your site. It is much better if you change the default out of stock notification to something that will encourage your customers to come back to your site.
Instead of the default notification, you can change it to something like “Temporarily out of stock, more inventory arriving soon.” This small change can be combined with an option to allow a customer to sign up for a notification when the item is back in stock. You can see how this is a much better way to retain a customer, than simply showing a default out of stock notification.
In this blog, we will show how to change Out of stock text on WooCommerce product pages and add your custom label instead of that.
How to Change The Default Out of Stock Notification in WooCommerce
Changing the Out of stock label for sold out products on WooCommerce is quite easy. All you need to do is add a few lines of PHP code into the functions.php file on the theme folder.
Fortunately, you don’t need to write any code yourself we’ve already done that part for you. All you need to do is copy the code from below and paste it into the functions.php file. In addition, be sure to replace the placeholder text in the code with your custom message.
Now that everything is ready, let’s get started.
- Open WordPress Theme Editor
Log in to the WordPress admin dashboard. And open the Theme Editor to access and edit your theme files. To access the Theme Editor, navigate to Appearance in the WordPress dashboard and click on Theme Editor.
- Open functions.php file
In the Theme Editor, you’ll see a text editor in the center and theme files listed on the right.
Scroll through the Theme Files list. Click on Theme Functions (functions.php) to open it in the editor.
- Copy the code snippet
add_filter('woocommerce_get_availability_text', 'themeprefix_change_soldout', 10, 2 );
/**
* Change Sold Out Text to Something Else
*/
function themeprefix_change_soldout ( $text, $product) {
if ( !$product->is_in_stock() ) {
$text = ‘<div class=””>Sold out.</div>’;
}
return $text;
}
- Add the code to function.php file
Scroll to the bottom of the functions.php file in the editor. Paste the copied code at the end.
- Edit the code snippet
The above code will replace the Out of stock with Sold out.
To show a custom message, replace ‘Sold out’ in the code with your preferred text.
After updating the text, click the ‘Save changes’ button. WooCommerce will now show your custom ‘Out of stock’ message.
Conclusion
The default “Out of stock” label for sold out products is quite plain. Replacing it with a more assuring message will help you to reduce the customer disappointment. Fortunately, it’s not that difficult to change it. Add the PHP code to your theme’s functions.php file. Replace the placeholder string with your custom message





Shares