Debut Theme: Display different delivery times based on inventory

Highlighted
New Member
2 0 0

Hi everyone!


We sell jewellery that is produced in our own workshop. Each product has several variants.
If a variant is out of stock, we would like to display a different delivery time.

If product variant stock > 0, display "Delivery time 3 days"
If product variant stock = 0, display "Delivery time 2 weeks"

I tried this piece of code I found somewhere:

{% if current_variant.available %}  
          {% if current_variant.inventory_quantity == 0 %}
            <div class="shipping-info">
                <p>
                  Delivery time 2 weeks
                </p>
            </div>
          {% else %}
          <div class="shipping-info">
              <p>
                Delivery time 3 days
              </p>
          </div>
          {% endif %}
{% else %}
	<div class="shipping-info">
                <p>
	out of stock
                </p>
            </div>
        {% endif %}

I placed it inside "product-template.liquid", and it seems to work, but the delivery message is not updating when the variant is changed, only on page reload.


So how could I get this to work properly? I am no coder, so detailed directions where to put what would be greatly appreciated!


Thanks in advance!

0 Likes
Highlighted
Shopify Expert
3474 543 819

HI @Aelian 

This code you did on liquid that only work for page load but no on variant change because on variant change it will call Js function in background so you have to do same code in Js.

You can find variant callback function in Asset->theme.js file fins "if(variants)" where you can see you function.

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes
Highlighted
New Member
2 0 0

Hi @Jasoliya,


Thanks for helping! I found the section in the theme.js file that handles variants, but I am a bit lost here. As I said, I am no coder. So how could I get the shipping info to update on variant change?

0 Likes
Highlighted
Shopify Expert
3474 543 819

Js is must theme base so can't send you code for that but i can juts suggest you want to solve your problem. as i told you in Variant callback function you have to manage all same thing that you manage in liquid, you can get all variant data in "variants" variant in this.

 

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes