Removing discount_code cookie if discount code removed on checkout

This is a very specific question. Hopefully, someone will have an answer to it.

We have many affiliates promoting our products at a discount. We therefore have an discount code for each affiliate and they use the “promote” link to pass on their discount code in the URL, which adds the cookie “discount_code”.

But as you know, discounts are not applied to any price until the checkout page.

To help alleviate confusion, we are looking for that cookie and cosmetically displaying the discount via JavaScript.

All this works well except for one circumstance: if, for whatever reason, the user manually deletes the coupon code on the checkout screen and returns to shopping, the cookie “discount_code” doesn’t get removed. So, we continue to show the discounted price even though no coupon is now attached to the checkout process.

Is there a better way to check for discount codes from a URL parameter or from the site session? Or is there a way to have that cookie deleted once someone has manually removed a coupon code?

I’m having a similar issue, were you able to ever get this resolved?

No. It looks like this is a problem on Shopify’s side. They don’t clear the cookie if you remove the discount code at checkout. Unless they rectify this, there really isn’t a way to manage it on the front end.

That’s unfortunate, thanks for the reply!

ACTUALLY! Your question prompted a quick brainstorm. I finally did it. I targeted the submit button on the tag removal form in the checkout liquid file. So, when they click the removal button, it also removes the cookie. I added this:

 // Target the "remove coupon" button and delete the discount_code cookie if clicked
document.querySelector('.tag__button').addEventListener('click', function() {
document.cookie = "discount_code=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
});

I haven’t wrapped it in a qualifying statement if the tag__button isn’t there, so I get an error in the console if there isn’t one, but I’m working on adding that right now.

Awesome, I’ll give that a try. Thank you!

New code with added if statement:

 // Target the "remove coupon" button and delete the discount_code cookie if clicked
const tag_btn = document.querySelector('.tag__button');
if (tag_btn !== null) {
tag_btn.addEventListener('click', function() {
document.cookie = "discount_code=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
});
}
1 Like

I have the same/similar problem. I deleted a discount code but the discount “button” is still there and - does not work of course. This is very confusing my customers.

I am using the shopify Dawn theme and I do not have a checkout liquid file. What the…

I’m not sure what issue you are displaying.

You deleted a discount code that had been applied, but you wonder why the discount box is still there? Or that you cannot apply another valid discount code after removing the previous one?

wonder why the discount box is still there

The discount box is always on the checkout page by default. In case someone wants to manually enter a code.

Every shopify expert that has deemed the discount code as something you have to live with is wrong.

It depends on your theme - but in my case - the Dawn theme version 2.0 and above there is an easy fix.

Go to your theme files. Search for “base” and open the base.css file.

Add the floowing to the bottom:

.order-summary .order-summary__section.order-summary__section–discount {
display: none;
border-top: none;
}

Poof ! Discount box gone !

Easy peasy.

May be different fo your theme but do a search and ignore the shopify naysayers.

Took me a while but the info is out there.

Well, I am surprised at the all caps snark, but I maybe I misunderstood the question. Your question seemed to be “why is it there after removing the discount code?”, not “how do I remove/hide it?”

I’m glad you found a solution to your issue.

BOTH questions applied to this scenario.

No snark intended.