A space to discuss online store customization, theme development, and Liquid templating.
Hi,
I want to know if it's possible to add a custom line item property in cart based on a condition.
Basically, I want to add the following {key: "Category", value: "Heavy"}, when the line item's price is more than $500.
What is the best way to do this?
Yes this is possible with javascript. You need to identify where the conditions can be found on the page and then pass them into a Javascript code, which will inject the attribute value into the cart form.
Hi @Ugurcan ,
Thank you for your reply. Can you guide me to the correct file which I need to look at? I tried doing it in main-cart-items.liquid but it didn't work.
It is different in every theme but you can start checking from parent file and follow partials from there. You can modify the code and add attributes or custom CSS classes to grab the values
Alright. Thank you. I will try to figure it out.
Does the data need to specifically be on the line item, or can it be part of the cart.
If so use cart attributes ca
I mention that because to update a LIP after it's in the cart is a bit more complicated than adding an input to a product form. You will need to either use the ajax api ,or make sure it's submitted as part of the cart-to-checkout.
https://shopify.dev/docs/themes/ajax-api/reference/cart
When using the ajax api make sure to preserve any existing LIP's on the line item, or you'll overwrite them (like tags on the rest api)
Contact paull.newton+shopifyforum@gmail.com 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
Hi @PaulNewton ,
Thanks for the insight. I think it will need to be Line Item Property as we want to use that as input to Shopify Functions. I don't think Cart Attributes are present in the Shopify's function input query.
https://shopify.dev/docs/api/functions/reference/payment-customization/graphql/common-objects/cart