variant.inventory_quantity ALTERNATIVE - How to show item inventory quantity (WITH VARIANTS)

Solved
Christopher33
New Member
2 0 1

Hi AquaParee!

This worked great! 

Can you assist with one more thing, if I have 10 or more of an item (let's say I have 90 of something) can you tell me how to make it just display '10+' vs. the actual number? 

Thank you for everything

0 Likes
AquaParee
Tourist
7 1 8

I would create a jQuery function to adjust the displayed number.

//not sure about this
if ($("#variant-inventory").html() > 10) { $("#variant-inventory").html("10+"); }
    else { $("#variant-inventory").html("{{ current_variant.inventory_quantity }}"); }

 

if this doesn't work, try removing the " " around "{{ current_variant.inventory_quantity }}" in my example.

You will then need to add this in your code at the section where you select your item in the first place, then on its variant change.

Christopher33
New Member
2 0 1

Hi/Thank you!

So I see this at first 

We currently have {{ current_variant.inventory_quantity }} in stock.
SOLD OUT
 
I removed the " " then it puts in the correct quantity... problem however the Search Functionality (Search Glass) at the top of the page stops functioning. I placed the code into theme.js for the Debut theme.
 
We're so close :). If you'd like me to contact you via e-mail please let me know - I'd be happy to provide a donation to you!
AquaParee
Tourist
7 1 8

if without my previous code the search bar was fine, it is probably a variable, class, or id problem. something must be interfering with your search bar.

Thank you for your offer, but I do not take donation. I am just a student trying to help fellow programmers  If you really want to do something for me, you could go on my LinkedIn profile and endorse me, it will help me become a trainee for a future employer.

good luck

My LinkedIn 

0 Likes
AquaParee
Tourist
7 1 8

This is an accepted solution.

This whole post is a solution btw lol

0 Likes
WTCT-DF
New Member
2 0 0

This shows the inventory for the default variant, but does not update when selecting a different variant.  I don't know why it isn't working for me when it obviously works for others.  Maybe a change in the theme since this was posted?

0 Likes