Skip to content

fix(modal-checkout): retrieve order from query vars in thankyou template#2324

Merged
adekbadek merged 4 commits intotrunkfrom
fix/modal-checkout-thankyou-order-retrieval
Apr 8, 2026
Merged

fix(modal-checkout): retrieve order from query vars in thankyou template#2324
adekbadek merged 4 commits intotrunkfrom
fix/modal-checkout-thankyou-order-retrieval

Conversation

@adekbadek
Copy link
Copy Markdown
Member

@adekbadek adekbadek commented Mar 24, 2026

All Submissions:

Changes proposed in this Pull Request:

When the modal checkout thankyou.php template is used as a replacement for global/form-login.php, WooCommerce does not provide the $order variable. This causes the thank-you page to fail because subsequent code depends on $order being set.

This fix retrieves the order from the URL query vars (order-received) when $order is not available, using the same approach WooCommerce uses in its order-received endpoint.

How to test the changes in this Pull Request:

  1. On trunk,
  2. Set up a Newspack site with WooCommerce and the modal checkout enabled (donations or memberships).
  3. Open the modal checkout
  4. Observe the logged warning:
image
  1. Switch to this branch, observe the warning gone

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 ran tests with your changes locally?

Copy link
Copy Markdown

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 a modal-checkout thank-you template edge case where WooCommerce doesn’t provide an $order object (notably when the template is used as a replacement for global/form-login.php), by reconstructing the order from the request so the thank-you UI can render reliably.

Changes:

  • Adds a fallback to load the WooCommerce order from the order-received query var when $order is not already set.
  • Keeps the existing order-key validation guard (key + hash_equals) to prevent displaying order details for invalid URLs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/modal-checkout/templates/thankyou.php Outdated
@adekbadek adekbadek marked this pull request as ready for review April 7, 2026 09:15
@adekbadek adekbadek requested a review from a team as a code owner April 7, 2026 09:15
@adekbadek adekbadek merged commit c483abd into trunk Apr 8, 2026
9 checks passed
@adekbadek adekbadek deleted the fix/modal-checkout-thankyou-order-retrieval branch April 8, 2026 12:59
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

Hey @adekbadek, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Apr 16, 2026
## [4.26.2-alpha.1](v4.26.1...v4.26.2-alpha.1) (2026-04-16)

### Bug Fixes

* **modal-checkout:** retrieve order from query vars in thankyou template ([#2324](#2324)) ([c483abd](c483abd))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 4.26.2-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants