Add custom line item property in cart.

sniper2804
Shopify Partner
391 25 67

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? 

Automate & bulk assign products to shipping profile: Auto Shipping Profiles: Shipr
Calculate accurate shipping rates: Shipping Calculator: ShipMagic
Hide, rename, reorder payment methods at checkout: Payment Customization: PayMix
Replies 6 (6)

Ugurcan
Shopify Expert
336 6 34

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.

 

Pasilobus, Inc - Shopify Experts -- www.pasilobus.com - Fast, efficient apps that do not slow down your store, Stellar support & Premier Services
sniper2804
Shopify Partner
391 25 67

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.

Automate & bulk assign products to shipping profile: Auto Shipping Profiles: Shipr
Calculate accurate shipping rates: Shipping Calculator: ShipMagic
Hide, rename, reorder payment methods at checkout: Payment Customization: PayMix
Ugurcan
Shopify Expert
336 6 34

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 

Pasilobus, Inc - Shopify Experts -- www.pasilobus.com - Fast, efficient apps that do not slow down your store, Stellar support & Premier Services
sniper2804
Shopify Partner
391 25 67

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

Automate & bulk assign products to shipping profile: Auto Shipping Profiles: Shipr
Calculate accurate shipping rates: Shipping Calculator: ShipMagic
Hide, rename, reorder payment methods at checkout: Payment Customization: PayMix

PaulNewton
Shopify Partner
6275 573 1323

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/... 

 

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)

 

 

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


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

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


sniper2804
Shopify Partner
391 25 67

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

Automate & bulk assign products to shipping profile: Auto Shipping Profiles: Shipr
Calculate accurate shipping rates: Shipping Calculator: ShipMagic
Hide, rename, reorder payment methods at checkout: Payment Customization: PayMix