Add custom line item property in cart

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

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

https://community.shopify.com/c/shopify-design/cart-use-cart-attributes-to-collect-more-information/m-p/613718

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)

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

1 Like

Alright. Thank you. I will try to figure it out.