Re: Show quantity selectors in the Cart, if the Stock quantity is greater >1, otherwise hide sele

Solved

Show quantity selectors in the Cart, if the Stock quantity is greater >1, otherwise hide selectors

artgazette
Excursionist
19 1 7

I am using the Studio Theme v15.0.1 (Password: "artgisback") and I have managed to successfully implement logic on the Product page (main-product.liquid), that IF stock is greater than 1, then show the quantity selectors, ELSE hide the selectors, and it works perfectly. I added on LINE 235 this code:

 

{% if product.selected_or_first_available_variant.inventory_quantity > 1 %}

 

But now I need to also update the CART, so that the same logic applies, as follows:

 

  1. IF the product/s in the cart have a stock quantity of greater than 1, then show the quantity selectors AND show the delete icon to remove products
  2. ELSE hide the quantity selectors, AND show the delete icon to remove products

cart-quantity-selectors.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Example of Product with >1 stock - you can see the Quantity selectors show on the Product page: https://artgazette-dev.myshopify.com/products/002-from-the-window-peruvian-rainforest-tambopata

 

Example of Product with only 1 stock item - you can see the Quantity selectors DO NOT show on the Product page: https://artgazette-dev.myshopify.com/products/01-an-ideal-for-living-21

 

Can someone guide me on the code to EDIT and ADD please?

First time Shopify store owner, looking to learn. Semi comfortable with CSS.
Accepted Solution (1)
artgazette
Excursionist
19 1 7

This is an accepted solution.

Thanks, your suggestion didn't solve it BUT it did help to get me onto the right path, and it needed to be:

 

{% if item.variant.inventory_quantity > 1 %}

 

THANKS for your help!

First time Shopify store owner, looking to learn. Semi comfortable with CSS.

View solution in original post

Replies 7 (7)

AK_Design_Dev
Shopify Partner
187 16 16

Hello @artgazette 

Yes, i can do this but i need to access your store i mean as staff member 

If you require further help to optimize your store, please don’t hesitate to reach out.


This contribution will always benefit you and you will get my full help easily and you can contact me easily.


Your Willpower Contribution Link:-

Contribution


Contact On My Mail :-[email protected]
artgazette
Excursionist
19 1 7

Sorry @AK_Design_Dev I'm on the BASIC plan, can't do that. Perhaps you can steer me? I saw in the main-cart-items.liquid where the selectors are managed, I assume in there, but not entirely surely on the logic and placement.

First time Shopify store owner, looking to learn. Semi comfortable with CSS.
AK_Design_Dev
Shopify Partner
187 16 16

okay okay then srry i can't helping you..

If you require further help to optimize your store, please don’t hesitate to reach out.


This contribution will always benefit you and you will get my full help easily and you can contact me easily.


Your Willpower Contribution Link:-

Contribution


Contact On My Mail :-[email protected]

PaulNewton
Shopify Partner
7192 635 1494

Hi @artgazette  studio is based on the Dawn reference theme

Add your quantity display logic to sections/main-cart.liquid and snippets/cart-drawer.liquid similar to the below files and lines

https://github.com/Shopify/dawn/blob/main/sections/main-cart-items.liquid#L243 

and https://github.com/Shopify/dawn/blob/main/snippets/cart-drawer.liquid#L277 

 

Though this does not account for removing the entire table column for quantity in the situation where no line-items have a quantity display.

 

Good Hunting. 

 

If you need this customization then contact me by my email for services.
Contact info in forum signature.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.

Contact [email protected] for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


artgazette
Excursionist
19 1 7

@PaulNewtonthanks for the steer. I tested and it works 50% 🙂 In the attached hyou can see that it removes ALL the Quantity selectors, where it should not have removed the first one (as Stock >1) and it should only have removed the second one, where Stock =1.

 

Any tips?

 

cart-quantity-selectors-2.jpg

 

 

 

First time Shopify store owner, looking to learn. Semi comfortable with CSS.
PaulNewton
Shopify Partner
7192 635 1494

Oh adjust it for the context of cart items, as this isn't a product page

See what type of output loop your in

https://github.com/Shopify/dawn/blob/main/sections/main-cart-items.liquid#L81C25-L81C30 

So it's probably just {% if item.inventory_quantity > 1 %} 

 

 

Contact [email protected] for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


artgazette
Excursionist
19 1 7

This is an accepted solution.

Thanks, your suggestion didn't solve it BUT it did help to get me onto the right path, and it needed to be:

 

{% if item.variant.inventory_quantity > 1 %}

 

THANKS for your help!

First time Shopify store owner, looking to learn. Semi comfortable with CSS.