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.
User | RANK |
---|---|
4 | |
2 | |
2 | |
1 | |
1 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023