Skip to content

fix(modal-checkout): tiered donate URL trigger handles non-default frequency#202

Draft
miguelpeixe wants to merge 2 commits into
mainfrom
fix/nppm-2815-tiered-modal-checkout-url
Draft

fix(modal-checkout): tiered donate URL trigger handles non-default frequency#202
miguelpeixe wants to merge 2 commits into
mainfrom
fix/nppm-2815-tiered-modal-checkout-url

Conversation

@miguelpeixe
Copy link
Copy Markdown
Member

All Submissions:

Changes proposed in this Pull Request:

Fix URL-triggered modal checkout for Donate blocks using the tiered layout when the URL's frequency parameter differs from the block's default frequency tab.

The tiered renderer emits a single hidden donation_frequency input pinned to the block's default frequency, so triggerDonationForm's early guard input[name="donation_frequency"][value="\${ frequency }"] returned null for any non-default frequency and the function bailed silently before reaching the tiered branch. (The URL params still got stripped because that happens after the trigger runs, so the failure was invisible to readers.)

The fix routes the tiered branch around that guard — only the frequency-based and untiered branches actually need that input — and scopes the frequency-tab lookup to the form (defensive against multiple donate blocks on a page).

Closes NPPM-2815.

How to test the changes in this Pull Request:

  1. On a Newspack site, set Suggested Donation settings to Tiered (Audience → Donations).
  2. Edit a page containing a Donate block and set its default frequency to Monthly.
  3. Open an incognito window (logged out) and visit each URL — confirm that all four now open the modal checkout with the correct frequency/amount, where previously only the month URLs worked:
    • ?checkout=1&type=donate&layout=tiered&frequency=month&amount=15 → $15.00 / month
    • ?checkout=1&type=donate&layout=tiered&frequency=month&amount=30 → $30.00 / month
    • ?checkout=1&type=donate&layout=tiered&frequency=once&amount=20 → $20.00 one-time
    • ?checkout=1&type=donate&layout=tiered&frequency=year&amount=360 → $360.00 / year
  4. Change the block's default frequency to Annual and re-test the year URL — still opens.
  5. Try an amount that isn't one of the tier amounts (e.g. &amount=999) — modal should not open (no regression to silent-fail on invalid params).
  6. Switch Suggested Donation to Frequency-based and test the same URLs with layout=frequency — confirm the frequency-based code path is unchanged.
  7. Switch to Untiered and test with layout=untiered — confirm the untiered code path is unchanged.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

…equency

The tiered donate form renders a single hidden donation_frequency input
locked to the block's default frequency, so triggerDonationForm's early
guard rejected any URL whose frequency differed from the default and the
modal never opened. Move the tiered branch ahead of the guard (only the
non-tiered branches need that input) and scope the frequency-tab lookup
to the form.

Fixes NPPM-2815
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes URL-parameter-triggered modal checkout for Donate blocks using the tiered layout when the URL’s frequency differs from the block’s default frequency, by bypassing the non-tiered donation_frequency input guard and scoping the frequency-tab lookup to the current form.

Changes:

  • Adjust triggerDonationForm so the tiered layout no longer relies on input[name="donation_frequency"][value="..."] existing/matching the URL frequency.
  • Scope tiered frequency-tab lookup to the current donation form to avoid cross-form interference on pages with multiple Donate blocks.

Comment thread plugins/newspack-blocks/src/modal-checkout/modal.js
Comment thread plugins/newspack-blocks/src/modal-checkout/modal.js
…gger

Switch from .forEach() to for...of so the URL-trigger handler returns
after the first form that matches, preventing duplicate submits on
pages with multiple .wpbnbd--platform-wc forms.

Addresses Copilot review feedback on #202.
@miguelpeixe miguelpeixe self-assigned this Jun 3, 2026
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.

2 participants