Personalized checkout and custom promotions with Shopify Scripts
Hi,
I was wondering if there was a good way to remove an item from the cart when the total of the cart drops under a specific amount after adding discount codes.
I found the property:
cart.line_items.delete_at(index)
and
cart.line_items.delete_if{}
These work but they don't actually remove the item. In my case when I remove the discount code, it auto adds that item back in.
It's a complecated requirement, let me know if I understand your requirement correctly.
You have a threshold order amount which impacts when a copy or discount will be their in cart.
You want to check if amount after discount if less than the threshold a item will be removed.
Question is how you will decide which item to be removed?
And want that item back in cart if discount is removed.
Let me know if anything I missed.
Not quite. So I already have a way to identify which line item to remove (line item property).
What I want to know is how to remove an item from the cart without it being added back. Currently, if my cart amount falls under a certain total (after applying discount), the item gets removed. My issue is that when the discount gets removed by the user, that removed item gets added back in automatically.
Not sure why that is happening if the cart.line_items.delete_if removes the item.
Not sure about cart.line_items.delete_if working.
You can keep the variant id in cookie when your script updating the cart and add again to cart when discount code removed.
So this is inside a Shopify Script, not sure I have access to cookies.
What I want to know is how to remove a line item using Shopify Scripts.
Use this
jQuery.post('/cart/change.js', { quantity: 0, id: '37667537027267' })
Assuming you already have jQuery on page.
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025