WooCommerce has become one of the popular eCommerce WordPress plugin and just exceeded 1 million downloads few months ago. Anyway, when more and more people are using the plugin, i believe you will come to a point when you need simple customization or tweak that will give you hard time as you are not coder or someone who know PHP.
Today, i would like to share how you actually can change default “In Stock” or “Out of Stock” text at WooCommerce product page. Let’s get started by giving you example:
1. You would like to change “In Stock” to “Available”
2. You would like to change “Out of Stock” to “Sold Out”
Step 1: Open your functions.php file at your current theme folder (wp-content/themes/[THEME]/functions.php) You can download functions.php file from FTP, edit then upload again, OR you cab go to WordPress Admin -> Appearance -> Editor, and click functions.php to edit then save.
Step 2: Put below code to the bottom of the file:
add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2); function custom_get_availability( $availability, $_product ) { //change text "In Stock' to 'SPECIAL ORDER' if ( $_product->is_in_stock() ) $availability['availability'] = __('AVAILABLE', 'woocommerce'); //change text "Out of Stock' to 'SOLD OUT' if ( !$_product->is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce'); return $availability; }
Final Step: Save the file above and done. You’ve told WooCommerce to get custom status for stock display at single pages. Hope you get some idea on how to tweak WooCommerce by reading more my articles.
Great filter thank you! Question…when you make this change it removes the quantity in stock. Can the filter above be altered so the inventory quantity is kept in the string?
changing “in stock” to “seats available”
Example: 10 seat available
Then as each seat is purchased…the number is reduced…as would the inventory level.
Thank you in advance for any help.
Joe
Hi Joe, i will try and update here again, thanks for your feedback.
Love you! Worked like a charm!
Thanks, glad it helped.
In reply to Joe,
I believe you need…
add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
function custom_get_availability( $availability, $_product ) {
global $product;
$stock = $product->get_total_stock();
if ( $_product->is_in_stock() ) $availability['availability'] = __($stock . ' AVAILABLE', 'woocommerce');
if ( !$_product->is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce');
return $availability;
}
Hello Terry & Jonny,
I also am trying to do the same thing as Joe, but the above code results in saying the total quantity of stock available. I have a variable ticket with four tiers, and it counts the total stock instead of the stock for the current item selected. I.E.
4 tiers of tickets with 50 tickets for each tier.
The above code results in 200 “in stock” instead of 50 when a single tier is selected. Do you know how to fix this?
Thank you !
First, Terry, thanks for this post, saved me from a headache.
Second, to get the stock back in there is not a cut & dry method, due to there are different types of products. In my instance, I have a variable product that has two variations, and will have 20 items split between the two, so I needed the total from the parent product and not the variation. My line now looks like this:
I figured out what I needed by dumping the $_product object to the screen by putting the following in the first line of the function:
If you follow that to the point of what you need, you should be able to figure out the object/array combination you need to call.
I have the very same problem with Brian. Do you guys know any solutions of that? Thanks!
Fansi
Hi Terry,
nice website with lots of great infos.
is it possible to show a linked button instead of the “sold out” note ?
the idea is to display a button that is linked to a page, form, in our case to a pop out that displays a from where people can fill in their email address to get notified from us when an item is back in stock.
thanks
Shorty
Thanks Terry,
It works like a charm… I just put it on my website Jam tangan original
Again thank you, you save the world
Hello,
This is just what is was looking for, except for the out of stoch i want to change the available in backorder text. SO in stock means deliviery within x days and ordering in backorder means xx days.
What extra text should i use?
Hi Brian not sure if you fixed this but for anyone else.. If you want to have the amount shown for each variations use the code below 🙂
Hi friend, great article! I am trying to change the text for “coupons” to “promo codes” or something else. Can this be done via the functions.php?
Thank you SO MUCH for this!!! It worked like a charm!
I removed the part about the In Stock change, and just kept the Out of Stock change, since that’s all I needed. I also changed “SOLD OUT” to “Call for Availability”. It worked GREAT!
Quick follow up question though…I noticed that now, WC puts a message box on the top of all the Out of Stock items that says “You cannot add “[Product Name]” to the cart because the product is out of stock.” I would like to change that to match my shiny new product stock listing, with something like: “You can not add “[Product Name]” to your cart, but we can order it for you. Please call us at xxx-xxx-xxxx for assistance.”
Can you help with that? Thanks! 🙂
Hi justin, you can put below code in your theme functions.php (source from Max Rice‘s blog post):
Hi when i copy paste the code into the editor i get this error:
Parse error: syntax error, unexpected T_FUNCTION
What happend?
Hi berend, you need to put the code in functions.php file within your active theme folder.
Thanks @terrytsang!
It looks like that code does something slightly different than what I was looking for, but very useful nonetheless! 🙂
I ended up just going to class-wc-cart.php and changing the wording in line 805.
(BTW…@berend: I found that I actually had to enter the code directly into the funtion.php folder in the FTP. Changing it in the editor always seemed to kick out weird results. Also, if I didn’t cut & paste the code in correctly the first time, it doesn’t edit right from the editor screen. Hope that helps! 🙂 )
Really appreciate the help!! Thanks!! 🙂
hello,
any idea how to completely hide the ‘sold out’ badge? it’s driving me mad.
Hi chris, do paste below code at theme functions.php to remove “Out of Stock’ text:
I have a small problem. I use this
But now it also shows Available, even when I haven’t filled in an amount of products available, I want it to be hidden when I haven’t filled in any number.
I’m sorry if my previous post wasn’t clear. The thing is I just want the “Available” to show, when I actually clicked “Enable stock management at product level (not needed if managing stock at variation level)” and filled in a number. Otherwise it doesn’t have to show anything.
Hi Jeru, you can try below code:
Hope this will solve your problem.
Thanks works like a charm! Great job helping people out here!
This is great. I have the same issue as Brian above — I have a product variation and want to report out the available inventory for each variation. I tried the solution suggested by Menzer above and that crashed my site. Terry’s suggestion immediately above works great but reports the total inventory across all variations. I can’t quite figure out how to combine the two options. Any further advice?
Thanks for sharing this and for the further comments on how to keep the number in stock showing etc. Worked brilliantly.
It’s my pleasure, Neil. Hope you continue supporting. Thanks.
Hello terrytsang, I have used this code and it works like a charm for the frontend, however in the admin area I am looking for a way to alter the ‘Out of Stock’ option there, as I have users which have access to the backend and the term out of stock is confusing for them as the product may not necessarily be out of stock, but they are not offering it for sale online. Do you know of the area or file where I can locate the text for out of stock to replace this option in the backend? It would be such a great help, I’ve searched other forums and I’m sure there must be a way around this I would really appreciate your help buddy.
Thanks for your info
Kind regards
Gary
The code worked brilliantly to change the ‘out of stock’ to ‘item sold’ on the product page itself as shown here:
http://www.asialuxurymarketplace.com/shop/fineart/lioness
However it has not changed the badge text on the product category page as shown here:
http://www.asialuxurymarketplace.com/product-category/fineart/papercute
Any ideas on how I can change the badge text on the category page will be very greatly appreciated. Thanks so much!
Hi Terry, is there any way to replace “In stock (Backorders Allowed)” to just “In Stock”? Thanks!
Do you know how to change the variable product message “Sorry, this product is unavailable. Please choose a different combination.”?
this code works great to change the out of stock message on the individual product page but how do i change the message that is shown in the store catalog page over the image?
http://legattigolf.com/stage/buy-putters-online/
hi i’m using a child theme and I tried this in childtheme functions.php and it took out my site nothing opens now just a blank white page i cannot even get into my wp admin 🙁
Thanks for the post Terry! Is there a way to specifically hide the “In stock” status but show the low stock message? I have it set in woocomm to show “only x left in stock vs in stock”.
I found a filter to change the the “only x left” to “ALMOST SOLD OUT” and styled it in red. But I don’t want the “in stock” to show as it’s also styled in red and is, I feel, a wasted page element from a conversion perspective.
Thanks for your insights! Keep up the great work!
Hi Jaime, you can add this code into your theme functions.php:
Hello all,
I need to make stock info visible only to list of registered users (in a group).
Can anyone help? Thanks
Pingback: Custom Text for In Stock and Out of Stock Text in Woocommerce | Sanjay Triumph
Terry, thanks for the code. It did work. However, I got 3 lines of code at the top of my website. It shows out of stock now, but there’s also an error. Do you know what it could be?
Thanks anyway! 🙂
Never mind. Ignore my first comment. I fixed. I’m a newbie…but I figured it out! lol
Hi Aline, glad it helped. Hope you enjoy learning.
HI Terry,
Your website has helped me a lot. If you go to my page http://www.krankmaui.com/product/gt-zaskar-20/
on the right hand side it says ‘out of stock’ , i would like to remove these words, however i want to keep this woo commerce product out of stock as i have a reservation script below and the attributes from being out of stock (showing the read more instead off add to cart button on thumbnail) is exactly what i want.. do you have any ideas? Thanks
Thank you! This was exactly what I needed.
You’re welcome, it’s my pleasure.
Hi Terry and all,
The code works perfectly with simple products.
How can I adapt to display the stock of a variation ?
Now, when you work on variation, it display only the parent product stock !
Thanks
Marc.
(sorry for my english…)
Is there any way to have the text changed for a search/results page as well? The code above is working great for product pages but not search/results pages. Thanks!!
Hi Terry,
Im trying to implement your code, but I want to show a message like “5-10 workingdays” if it’s out of stock. But they do need to be able to order the product. So I thought I need something to add such as ‘if stock is 0 or less, than show message 5-10workingdays’, but I have no clue on how to do this. Implementing the previous code from Jamie and adapting it a bit, led to chrashing the website. So could you please help me for this problem?
Thanks in advance!
Digging up an old but really needed thread.
So Far: I’m using variable products:
I use this code
” If you want to have the amount shown for each variations use the code below”
add_filter( ‘woocommerce_get_availability’, ‘custom_get_availability’, 1, 2);
function custom_get_availability( $availability, $_product ) {
global $product;
$stock = $_product->get_stock_quantity( );
if ( $_product->is_in_stock() ) $availability[‘availability’] = __($stock . ‘ AVAILABLE’, ‘woocommerce’);
if ( !$_product->is_in_stock() ) $availability[‘availability’] = __(‘FULLY BOOKED! – PLEASE SELECT ANOTHER DATE’, ‘woocommerce’);
return $availability;
}
But now it also shows Available, even when I haven’t filled in an amount of products available, I want it to be hidden when I haven’t filled in any number.
This is discussed above and I see there is a snipet code in this thread to fix that but not for variations.
This code works but not for variations, seems i need to combine parts of the 2 snippet codes.
Ive tried putting this in //Don’t do anything if managing stock is not checked
But i am stuck, can you assist?
Thanks in advance
Hi Terry, regarding changing the backorder avaialble text, I used to have it work with my previous theme.I just changed to another theme, and it doesn’t seems to work. What do you think it goes wrong?
Here is a screenshot of my theme-child/functions.php
https://dl.dropboxusercontent.com/u/26630687/Screenshot%202015-06-08%2014.23.16.png
Thanks in advance!
This is such a great website, so useful for me as a developer.
I really need 3 stock options but I do not know how to add and extra one, I need the stock options to be For Sale, Sale Agreed, Sold.
How do I do this and have those options show in the admin rather than In stock and out of stock?
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; }
That will change “Out of Stock” to read “Sold!” instead.
Hi,
I’ve got your original posted code working to change the out of stock message on my individual product pages, but I would also like to change the message on the product archive pages (eg Shop page, product category page).
These are controlled by my child theme/woocommerce/archive-product.php, but this file doesn’t have the out of stock code – it calls a woocommerce loop – is there a simple way to globally control this? I tried 2 plugins (Stock message + WooCommerce Out of Stock Message) but they are working for the product archives.
aybe it’s specific to my theme ( http://flatsome.uxthemes.com/) / or my child theme
Any suggestions would be much appreciated.
Thanks
Awesome! But I see that function is escaping all the HTML I put in there. How can I do to show some colors and bold letters?
Thank you so much for this – I would also like to include a link where they can add themselves to a waiting list, but my html is out put as text. How can I output the message as HTML?
I would love to know if you had an answer for how to have to “Out of Stock” text changed on the product catalog (archive) and not just the individual products page.
In my case, I would love for the images in the catalog to have “Coming Soon!” across the top instead of “Out of Stock”.
I look forward to your response. Your solution for the product page itself is one of the cleanest I have found. Great work!
this code works great to change the out of stock message on the individual produc
Hi,
You can use this plugin https://wordpress.org/plugins/woo-custom-stock-status
thanks
Thanks for the Plugin… https://wordpress.org/plugins/woo-custom-stock-status
It worked nicely for my individual products: http://mixedmediaart.co.uk/index.php/product/a-hint-of-summer/
But not for my shop/category page: http://mixedmediaart.co.uk/index.php/shop/
I look forward to your new release.
Many thanks… 🙂
Thank you for the code Terry, very helpful!
As some one mentioned, same for me, it only changed the text on the single product page, which was good.
But my theme still showed “Out of stock” on the category pages, for the flatsome theme. I fixed it by changed the text in the woocommerce/content-product.php page. Line 62. Easy simple fix without another plugin needed.
Just in case some one else is wondering the same 🙂
Thanks again for posting this.
This is great info but what i really need is a way to add an additional option. We are manufacturers, some of our equipment is large (think riding lawnmowers) and is made to order while others are ‘ready to ship’. How can I ADD an option to the dropdown selection. I tried changing the abstract-wc-product.php from $status = ( ‘outofstock’ === $status ) ? ‘outofstock’ : ‘instock’; ***TO*** $status = ( ‘outofstock’ === $status ) ? ‘outofstock’ : ‘instock’: ‘preorder’; but not working.