Skip to content

Skip auto-applying EDD discount when product requirements aren't met#185

Open
zackkatz wants to merge 3 commits intostrangerstudios:devfrom
GravityKit:fix/edd-skip-invalid-discount-auto-apply
Open

Skip auto-applying EDD discount when product requirements aren't met#185
zackkatz wants to merge 3 commits intostrangerstudios:devfrom
GravityKit:fix/edd-skip-invalid-discount-auto-apply

Conversation

@zackkatz
Copy link
Copy Markdown

@zackkatz zackkatz commented Mar 5, 2026

Summary

  • When Sitewide Sales auto-applies an EDD discount via automatic_coupon_application(), it now checks if the cart contents satisfy the discount's product requirements before applying
  • If requirements aren't met (e.g., lifetime products in cart with an annual-only discount), the discount is silently skipped instead of being applied and then rejected by EDD with a confusing "product requirements not met" error
  • Uses EDD's own is_product_requirements_met(false) — the false parameter suppresses error messages in the session

Test plan

  • Configure a Sitewide Sale with an EDD discount that has product requirements (e.g., only annual price IDs)
  • Add a product/price that IS in the requirements — discount should auto-apply normally
  • Add a product/price that is NOT in the requirements (e.g., lifetime) — discount should be silently skipped, no error shown
  • With an empty cart, visit the site — no errors, discount ready to apply when eligible items are added
  • Verify the discount still auto-applies correctly on the landing page with eligible products

zackkatz added 3 commits March 4, 2026 20:51
When Sitewide Sales auto-applies an EDD discount, check if the cart
contents satisfy the discount's product requirements first. If not
(e.g., lifetime products in cart with an annual-only discount), silently
skip applying rather than letting EDD reject it with a confusing error.

Uses EDD's own is_product_requirements_met(false) to check without
setting error messages in the session.

Fixes strangerstudios#183
The product requirements check was preventing the discount from being
set in the session on product pages. Restrict the check to the checkout
page so sale pricing still displays on product pages.

- Add edd_is_checkout() guard before product requirements check
- Fixes regression from f2244ec
When a sitewide sale discount was auto-applied during browsing (empty
cart), it persisted in the EDD session. If the customer then added a
Lifetime product and went to checkout, the stale discount caused
checkout to fail.

Now checks product requirements on every page load (not just checkout)
and actively removes the discount from both cart_discounts and
preset_discount when requirements aren't met. Strike-through pricing
on product pages is unaffected since it calculates directly from the
EDD_Discount object without using the session.
@zackkatz
Copy link
Copy Markdown
Author

@flintfromthebasement What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant