The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Is it possible to remove coupon from cart if subscription product is removed from cart?

mattvarumattvaru Member
in Help edited June 2019
Hi all,

I'm hoping someone can help me figure out a solution to this issue.

I have some subscription products set-up in my store and they're set-up in the following quantities: 1 product/month, 2 products/month, 6 products/month, and 12 products/month. (Each subscription item has a unique SKU/product code.)

I have 4 discount codes - one for each quantity, so:
- 1 Product (10% off)
- 2 Products (15% off)
- 4 Products (20% off)
- 6 Products (25% off)

The coupon code is passed with the add-to-cart URL as a param and is restricted by product code in Foxy to prevent misuse.

The issue I'm running into is the following scenario:

Let's say a user adds a 1 product/month subscription to their cart. They change their mind, remove the item from the cart, and then go to try and add another subscription product. They're hit with an error along the lines of "coupons are not combinable" (I don't want to make them combinable if I can avoid it.)

So when they add the new subscription product, no discount gets applied. Is there a way to remove the coupon code altogether if the product is removed from the cart?

Thanks in advance!
  • fc_marijafc_marija FoxyCart Team
    Hi @mattvaru-

    You can do that. We have a snippet that adds/removes a coupon based upon the item in the cart. It would probably be simpler to remove the coupon code being added with the add-to-cart URL and add it using this code instead, but you could modify the code to remove the part where it's added. You'll need to adjust it to run for multiple products.

    I think you have some scripting experience, correct? If so, customizing the snippet should be pretty simple, but if you need help, don't hesitate to let us know. Here's the snippet:
  • Hi @fc_marija - thanks for getting back to me so quickly! Apologies for my delay.

    Thanks so much for sending that over — I had no idea that article existed. I took a look and think I should be able to figure it out, but if I can't, I'll send you a whisper. Appreciate you!
  • mattvarumattvaru Member
    edited June 2019
    Hi @fc_marija - I think I got a basic version up-and-running and can flesh out the full version tomorrow, but I was wondering whether it's possible to have this script run for the sidecart too, prior to coming to checkout. Is that doable? I tried changing the {% if context == 'checkout' %} to {% if context == "checkout" or context == "cart" %} but to no avail.
  • fc_adamfc_adam FoxyCart Team

    Good question. Your approach would have output the javascript on the cart (and sidecart) successfully, but none of the events would have executed when the sidecart as initially opened. If you keep that edit you made, and add the following near the top of the script tag with the other events, it should work for you then:
    FC.client.on("cart-submit.done", checkPromoProducts);
  • Ahh, awesome! Works great. Thanks so much to both you and @fc_marija!
  • fc_marijafc_marija FoxyCart Team
    Great to hear it's working for you, @mattvaru
Sign In or Register to comment.