skip to Main Content

On Shopify, I got this code to display available quantities in stock with a pretty visual effect on product page, but it don’t refresh on product with variants. I’m looking for a way to update stock availibility after variant changes, based on this code (without refreshing the page).

        Refresh Stock Availability After Variant Changes
    {% assign current_variant = product.selected_or_first_available_variant %}
        <div class="instock-pulse">
          {% if current_variant.available %}
          {% if current_variant.inventory_quantity > 0 %}<span class="icon--pulsing"></span>{{ current_variant.inventory_quantity }} pieces in stock
          {% endif %}
          {% endif %}
        </div>

2

Answers


  1. You’d need to hook into the variant update function in the JavaScript and then update that span with the current variants inventory amount.

    Liquid is compiled on the server, so any updates to the page need to be made with JS

    Login or Signup to reply.
  2. If you are using Dawn Theme you can easily do that by just using your code snippet in the correct place. As Dawn theme is updating HTML using ajax.

    If you are using another theme then we need to check and if it’s updated by js, if so then we need to write js code to update variant Stock. (you can share access of store i can help you with it if needed)

    enter image description here

    Expected output

    enter image description here

    if any doubt please comment.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search