How to Display “In Stock” Availability on WooCommerce Product Pages

By default, WooCommerce doesn’t display the “in stock” status or availability on the product page. While this is an expected standard for online shoppers these days I am still surprised why this is the case. Since I found the solution, I wanted to share it with you since I know you’re not the only one who will find this little WooCommerce modification useful.

Why Show an “In Stock” Message?

“In Stock” or “Out of Stock”, which ever the case may be, showing the availability status even if you never, ever run out of stock in an item helps conversion rates because it provides a signal to the customer that it is in fact in stock. Whether or not you decide to show how many are available or show low stock quantities, a simple, “In Stock”, can be the most helpful thing when shopping online.

Here’s How to Show “In Stock”

  1. In your WordPress admin, navigate to Appearance > Editor.
  2. Click functions.php on the right.
  3. Go to the bottom of the file and paste the following code then save.




// Hook in
add_filter( 'woocommerce_get_availability', 'custom_override_get_availability', 10, 2);
 
// The hook in function $availability is passed via the filter!
function custom_override_get_availability( $availability, $_product ) {
if ( $_product->is_in_stock() ) $availability['availability'] = __('In stock', 'woocommerce');
return $availability;
}

Is Your Product In Stock?

woocommerce-show-in-stock-status

Let me know if this worked for you or if you found another way how to do this.

Related Posts

18 responses to “How to Display “In Stock” Availability on WooCommerce Product Pages”

  1. jake Avatar
    jake

    THANKS. THIS IS A GREAT SNIPPET! I just used it and it works =) thanks again!

  2. Chris Avatar
    Chris

    I get
    Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home/mysite/public_html/sfdemo/wp-content/themes/sfdemo/functions.php on line 62

    Sadly not working :-/

    1. Jannis Avatar
      Jannis

      You get the parsing error probably because you made the same mistake as me and copied it without checking it again. Check if you copy the numbers 1-8 with it aswell. They are not part of the code. The function starts at “add_filter( ‘woocommerce_get_availability’, ‘custom_override_get_availability’, 1, 2);”

      1. Cristi Avatar
        Cristi

        He’s right, there is a mistake at line 2:

        add_filter( ‘woocommerce_get_availability’, ‘custom_override_get_availability’, 1, 2);

        It should be:

        add_filter( ‘woocommerce_get_availability’, ‘custom_override_get_availability’, 10, 2);

        1. King Rosales Avatar
          King Rosales

          Thanks Cristi, I’ll update the code!

  3. Shanks Avatar
    Shanks

    Can I have this feature for variable products to?
    I wish to have “Availability : In Stock” by default (my varible product will only have products in stock dropdown choices)
    I tried this but not working on products with variations

  4. Jim Avatar

    Can I do this with multilingual site?

  5. Paulo Avatar

    For proper translation handling you need to match the string to the WooCommerce original and write ‘In stock’, with a lowercase ‘s’, like so:

    if ( $_product->is_in_stock() ) $availability['availability'] = __('In Stock', 'woocommerce');
  6. Paulo Avatar

    For proper translation handling you need to match the string to the WooCommerce original and write ‘In stock’, with a lowercase ‘s’, like so:

    if ( $_product->is_in_stock() ) $availability['availability'] = __('In stock', 'woocommerce');
    1. JohnDoe;) Avatar
      JohnDoe;)

      Confirmed, you have to use ‘In stock’ with a lower case S to support other languages

  7. Luis Villegas Avatar
    Luis Villegas

    Still working, thanks dude!

  8. Vlad Avatar
    Vlad

    Not working in Woocommerce ver. 3+

  9. Md. Zahidul Islam Avatar
    Md. Zahidul Islam

    Oh, thanks.

    I am developing a Woocommerce plugin. I manipulated the string successfully.

    1. King Rosales Avatar
      King Rosales

      thats awesome!!

  10. klaus Avatar
    klaus

    It is probably not possible to to use an image instead of text?

    1. King Rosales Avatar
      King Rosales

      Hi Klaus, yes absolutely. You can use an image instead by using instead of

      or etc.

  11. Reggie Avatar
    Reggie

    Not working. Any chance you fix it to work on the current WooCommerce? Many thanks <3

  12. Arpa Avatar
    Arpa

    we have a few categories that have products that never go out of stock (I mean, even if we run out of stock, we accept orders in an unlimited number)

    So, we want to show “In Stock” on those categories’ products, even if the products are actually low stock or out of stock.

    is there a code to override this in some categories?

    Thanks

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.