woocommerce

How to change In Stock or Out of Stock text in WooCommerce

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.

59 thoughts on “How to change In Stock or Out of Stock text in WooCommerce”

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

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

  3. 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 !

  4. 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:

    if ( $_product->is_in_stock() ) $availability[‘availability’] = __($_product->parent->total_stock .’ AVAILABLE’, ‘woocommerce’);

    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:

    echo “\$_product: “. __LINE__ .”\n\n”. nl2br(preg_replace(“/ /U”, ” “, htmlspecialchars(print_r($_product, TRUE)))).”\n\n”;

    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.

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

  6. 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?

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

    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;
    }
  8. 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?

  9. 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! 🙂

    1. Hi justin, you can put below code in your theme functions.php (source from Max Rice‘s blog post):

      // rename the coupon field on the cart page
      function woocommerce_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
      
      	// bail if not modifying frontend woocommerce text
      	if ( is_admin() || 'woocommerce' !== $text_domain ) {
      		return $translated_text;
      	}
      
      	if ( 'Apply Coupon' === $text ) {
      		$translated_text = 'Apply Promo Code';
      	}
      
      	return $translated_text;
      }
      add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_cart', 10, 3 );
      
      // rename the "Have a Coupon?" message on the checkout page
      function woocommerce_rename_coupon_message_on_checkout() {
      
      	return 'Have a Promo Code?';
      }
      add_filter( 'woocommerce_checkout_coupon_message', 'woocommerce_rename_coupon_message_on_checkout' );
      
      // rename the coupon field on the checkout page
      function woocommerce_rename_coupon_field_on_checkout( $translated_text, $text, $text_domain ) {
      
      	// bail if not modifying frontend woocommerce text
      	if ( is_admin() || 'woocommerce' !== $text_domain ) {
      		return $translated_text;
      	}
      
      	if ( 'Coupon code' === $text ) {
      		$translated_text = 'Promo Code';
      	} elseif ( 'Apply Coupon' === $text ) {
      		$translated_text = 'Apply Promo Code';
      	}
      
      	return $translated_text;
      }
      add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_checkout', 10, 3 );
  10. Hi when i copy paste the code into the editor i get this error:

    Parse error: syntax error, unexpected T_FUNCTION

    What happend?

  11. 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!! 🙂

    1. Hi chris, do paste below code at theme functions.php to remove “Out of Stock’ text:

      add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
      function custom_get_availability( $availability, $_product ) {
        if ( !$_product->is_in_stock() ) $availability['availability'] = '';
        return $availability;
      }
  12. I have a small problem. I use this

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

    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.

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

    1. Hi Jeru, you can try below code:

      add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
      
      function custom_get_availability( $availability, $_product ) {
      	global $product;
      	$stock = $product->get_total_stock();
      
      	//Don't do anything if managing stock is not checked
      	if(!$_product->managing_stock()) return $availability;
      
      	//Change default 'In Stock' and 'Out of Stock' text
      	if ( $_product->is_in_stock () ) $availability['availability'] = __($stock . ' Available', 'woocommerce');
      	if ( !$_product->is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce');
      
      	return $availability;
      }
      

      Hope this will solve your problem.

  14. 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?

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

  16. Hi Terry, is there any way to replace “In stock (Backorders Allowed)” to just “In Stock”? Thanks!

  17. Do you know how to change the variable product message “Sorry, this product is unavailable. Please choose a different combination.”?

  18. 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 🙁

  19. 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!

    function custom_stock_totals($availability_html, $availability_text, $product) {
    	if (substr($availability_text,0, 4)=="Only") {
    		$availability_text = "Low Stock";
    	} 
    	$availability_html = '' . esc_html( $availability_text ) . '';
    	return 	$availability_html;
    }
    add_filter('woocommerce_stock_html', 'custom_stock_totals', 20, 3);
    1. Hi Jaime, you can add this code into your theme functions.php:

      add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
        
      function custom_get_availability( $availability, $_product ) {
          //hide text "In Stock'
          if ( $_product->is_in_stock() ) $availability['availability'] = '';
      }
      
  20. Pingback: Custom Text for In Stock and Out of Stock Text in Woocommerce | Sanjay Triumph

  21. 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! 🙂

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

  23. 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…)

  24. 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!!

  25. 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!

  26. patrick Williams

    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

  27. Patrick Quirke

    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?

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

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

  30. 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?

  31. 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?

  32. 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!

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

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

Leave a Comment

Your email address will not be published. Required fields are marked *