Product description based on inventory level

Highlighted
New Member
1 0 0

Hi,

Im trying to change the product-template.liquid code to show a different delivery time based on the inventory level (if the variant is in stock, then the product is delivered within 2-4 days, if not, it's 1-2 weeks).

I added this code to the product-template.liquid

<h4 class="delivery-text">
  {% if product.selected_or_first_available_variant.inventory_quantity > 0 %}
    Delivery time: 2-4 days
  {% else %}
    Delivery time: 1-2 weeks
  {% endif %}
</h4>

 

In the variantCallback function in the theme.js.liquid i added this code:

    if (variant.available) {
      if (variant.inventory_quantity > 3) {
        $('.delivery-text', $product).text('Delivery time: 2-4 days');
      } else {
        $('.delivery-text', $product).text('Delivery time: 1-2 weeks');
      }
    } else {
      $('.delivery-text', $product).empty();
    }

 

However, the delivery time does not seem to change when I select different variants on the product page. It's just stuck with the first variant.

Anyone has any advice? I'd reallly appreciate!

Edit: I'm using the Supply theme btw

0 Likes