Puri.io Team working by the pool

Change WooCommerce “Out of Stock” Messages Guide

The default out of stock messages in WooCommerce aren’t friendliest for customers. This guide will show you how you can change and customize any of the out of stock or in stock messages.

Changing Product “Out of stock” to “Sold out”

Simple products will have the default “out of stock” message. It’s really easy to change this to display another message, such as sold out or anything else. We need to access the woocommerce_get_availability_text filter to change the availabilty message. We can also change the available stock message.

Advanced users can tap into the product details and create unique messages based on any conditions. For example, one condition could be if the product is in a specfic category or not. I’ll include some bonus product conditions at the bottom for you to mix and match.

/** * Change "Out of stock" to "Sold Out" * @param string $text * @param WC_Product $product * @return string */ function puri_woocommerce_get_availability_text( $text, $product ) { if (!$product->is_in_stock()) { $text = 'Sold out'; } else { // You can add more conditions here. e.g if product is available. // $text = 'Available right now'; } return $text; } add_filter( 'woocommerce_get_availability_text', 'puri_woocommerce_get_availability_text', 999, 2);
Code language: PHP (php)

Changing “product is currently out of stock” message on variable products

Variable products have the default out of stock message “This product is currently out of stock and unavailable.” The WooCommerce filter we need to change is woocommerce_out_of_stock_message. Let’s change it via PHP functions.

You can add the below function your child theme’s functions.php or a custom plugin.

/** * Out of stock message for product variations. * @param string $text default message. * @return string */ function puri_out_of_stock_message( $text ){ $text = 'This product is currently sold out, check back again soon.'; return $text; } add_filter( 'woocommerce_out_of_stock_message', 'puri_out_of_stock_message', 999);
Code language: PHP (php)

You can replace the default message with your own text. For example, “This product is currently sold out, check back again soon” could be a little more inviting.

Conditional WooCommerce “out of stock” messages

You can conditionally apply a specifc out of stock message per product or product category. Here are a couple of examples to get you started. These snippets can be used within the above functions.

// Assuming you have access to the $product object. // If the product has category if( !has_term( 'uncategorized', 'product_cat', $product->get_id() )){ $text = 'uncategorized products are restocked every friday'; } // If the product is a specific product by ID. if( $product->get_id() == '123' )){ $text = 'This product is only restocked every friday'; }
Code language: PHP (php)

Wrapping up

These snippets are fully compatabile with WooCommerce 3.0 and WooCommerce 4.0.

Let me know what you are replacing the out of stock messages with. I’d love to hear your ideas and reasoning!

Default image
I write the code and make everything work. Got a question? Write it below 😊
Articles: 17