New Shopify Certification now available: Liquid Storefronts for Theme Developers

How to display "in stock" and Icon in product pages of Dawn theme?

gievy
Visitor
1 0 0

Hello, I want to achive something like in the photo below on my Dawn theme. Anyone knows how to code / implement this? Or maybe there is a special app for that? (Been looking in app store and found nothing)

Screenshot 2023-02-17 at 14.26.16.png

Replies 2 (2)
mics
Trailblazer
172 12 29

To add the "In Stock" text and icon to product pages on the Dawn theme, you can follow these steps:

  1. From your Shopify admin, click on "Online Store" and then click on "Themes".
  2. Find the Dawn theme and click on "Actions" > "Edit Code".
  3. In the left-hand menu, click on "Sections" and then click on the "product-template.liquid" file to open it.
  4. Find the section of code that outputs the product price. This should look something like:

Code:

{% if product.price %} <span class="product-price"> {{ product.price | money }} </span> {% endif %}

  1. Add the following code immediately after the product price code:

phpCopy code

{% if product.available %} <p class="product-stock"> In Stock <svg class="icon icon--check" viewBox="0 0 20 20"> <path d="M18.3 3.7c-.4-.4-1-.4-1.4 0L8 12.6 3.1 7.7c-.4-.4-1-.4-1.4 0s-.4 1 0 1.4l5 5c.2.2.5.3.7.3s.5-.1.7-.3l10-10c.4-.4.4-1 0-1.4z"></path> </svg> </p> {% else %} <p class="product-stock out-of-stock"> Out of Stock </p> {% endif %}

This will add an "In Stock" message and checkmark icon to product pages if the product is available. If the product is not available, it will display an "Out of Stock" message instead.

  1. Click "Save" to apply the changes to your theme.

You can customize the "In Stock" text and icon by editing the relevant HTML and SVG code in the above example.

 

banned
Mireta
Tourist
5 0 0

Thanks for your help. The code works but only for the variant that loaded first. The text doesn't change when choosing other variants. Do you have a different code that show the stock status of a variant and changes accordingly? I think it may need a use of a javescript but I couldn't figure it out.