There are various ways to handle stock within WooCommerce. When your products are out of stock and you do not allow backorders for the product, WooCommerce will show a ‘Out of stock’ type of message. Here’s an example with the Storefront theme.
If you sell custom, unique or otherwise limited stock you may want to change the ‘Out of stock’ message to be more descriptive. When a product says ‘Out of stock’ it may indicate to customers it may return in stock over time, while for those unique or custom items this will not be the case.
For those kinds of products a ‘Sold’ or ‘Sold out’ message will more clearly communicate to customers that it will not return back in stock. To change the default ‘Out of stock’ messaging a small code snippet is required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
About the author:Jeroen Sormani is actively building WordPress, WooCommerce and Easy Digital Downloads plugins. Slightly obsessed by writing high quality code. Follow Jeroen on Twitter
2 comments
Is there a way to also change the “In Stock” message with this code? When I try to do it using other code I find, it messes up this code. I want it to read “In Stock” vs. “In Stock (Can Be Backordered)”
Sure, you can change the first bit to change the text when in stock instead of when its out of stock; if ( $product->is_in_stock() ) { – removing the exclamation mark.
Is there a way to also change the “In Stock” message with this code? When I try to do it using other code I find, it messes up this code. I want it to read “In Stock” vs. “In Stock (Can Be Backordered)”
Hi,
Sure, you can change the first bit to change the text when in stock instead of when its out of stock;
if ( $product->is_in_stock() ) {
– removing the exclamation mark.Cheers,
Jeroen