Remove GWP item from checkout if the discount code is changed

Shopify Partner
16 0 3

Hi all.

I've created GWP option in Shopify using Liquid and JS.

So if the user has X value in the cart he gets a free product, the product has a value and when the user redirects the checkout I add a discount code attached and the user gets it for free using that discount.

The problem is, we don't want the users to use other discounts with this. So when they change and add a new discount code in the checkout current discount is removed but the gift item remains in the cart and they are charged for that. Is there any way I can remove the item with the discount code?

I know we can do this from Shopify+ using Shopify script, but this is not a Shopify+ store

Thank you!



Thank you!