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.

  1. 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.

Accessing Theme Editor from Appearance menu in WordPress to change WooCommerce out of stock message.

  1. Open functions.php file

In the Theme Editor, you’ll see a text editor in the center and theme files listed on the right.

WordPress Theme Editor showing functions.php and style.css files to modify WooCommerce out of stock text.

Scroll through the Theme Files list. Click on Theme Functions (functions.php) to open it in the editor.

Editing functions.php in WordPress Theme Editor to change WooCommerce out of stock text.

  1. 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;
}

  1. 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.

Adding custom code to functions.php to change WooCommerce out of stock text in WordPress.

  1. Edit the code snippet

The above code will replace the Out of stock with Sold out.

Image error message stating 'There was an error processing this image' on a gray background.

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