How to add "In Stock" message on product page?

magicwheels
Visitor
2 0 0

Hello,
I would like to be able to display "In Stock" label on the product page for customers to see when they view a product that is in stock. I am using the "Supply" theme. Google merchant center requires that display function now.

Currently, the theme only displays a "sold out" label for products that are out of stock on the individual product pages.

How would I go about doing this?
Thank you.

Replies 6 (6)

Hardik29418
Shopify Partner
2858 407 1073

@magicwheels 

Please Go to Online Store -> Themes -> Edit code -> Sections -> product-template.liquid and paste this code whereever you want to set.

{% if product.selected_or_first_available_variant.available == true %}
    <p>In Stock</p>
{% endif %}

 

- Need a Shopify developer? Chat on WhatsApp or EMAIL ME!


- Your Coffee Tip would do Magic code ❤️
- For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
- Email
magicwheels
Visitor
2 0 0

Thank you very much for help, I have pasted into the  product-template.liquid section, but the "In Stock" sign didn't show up, may be I pasted to wrong position? is there a specific line I should paste? thanks

dmwwebartisan
Shopify Partner
12280 2546 3694

@magicwheels 

Please share your Sections/product-template.liquid  file code .

Thanks!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app

dmwwebartisan
Shopify Partner
12280 2546 3694

@magicwheels 

Please Go to Online Store -> Themes -> Edit code -> Sections -> product-template.liquid and paste this code whereever you want to set.

{% comment %} Inventory tracking on product page {% endcomment %}
            <div id="variant-inventory" class="{% unless current_variant.available %} hide {% endunless %}">
              {% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
              We have {{ current_variant.inventory_quantity }} in stock.
              {% else %}
              This product is available.
              {% endif %}
            </div>
If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app
IsmailTalb
Shopify Partner
3 0 0

"current_variant" variable needs to be defined like so : 

{% assign current_variant = product.selected_or_first_available_variant %}

so the full code will be something like : => 


 

{% assign current_variant = product.selected_or_first_available_variant %}

<div id="variant-inventory" class="{% unless current_variant.available %} hide {% endunless %}"> {% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %} We have {{ current_variant.inventory_quantity }} in stock. {% else %} This product is available. {% endif %} </div>

 

 

or alternatively you can only check for inventory_quantity > 0


 

<div id="xyz" class="{% unless current_variant.available %} hide {% endunless %}"> 
              {% if  current_variant.inventory_quantity  > 0 or current_variant.inventory_policy != "continue" %}
                    <span class="in-stock">  In stock</span>
              
              {% endif %}
  </div>

 




 


 

BSHOCKEDELEC
Visitor
1 0 0

Hi All 

So everyone here seems to be trying what I have just discovered 

I please need help with my code, I cannot seem to get it right?

I also want labels that show something is in stock or out of stock? (and still continue to take orders from cleints)