fix(modal-checkout): open checkout for variation_id URL triggers#163
fix(modal-checkout): open checkout for variation_id URL triggers#163rbcorrales wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes modal-checkout URL triggers for checkout_button so links that include variation_id reliably open the checkout modal for the exact requested variation (or grouped child), including variable-subscription products, and avoids silent fallbacks when no matching form/picker exists.
Changes:
- Add DOM helper utilities to resolve the correct checkout form (exact locked button vs. picker selection) and safely parse
data-checkoutwithout throwing. - Update modal URL-trigger handling to (a) submit only when a matching form is found and (b) keep URL params intact + log a warning when resolution fails.
- Ensure variable-subscription products render a variation picker modal and fix product-type detection for tiers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/newspack-plugin/includes/plugins/woocommerce-subscriptions/class-subscriptions-tiers.php | Fixes variable-subscription product type check so tiers logic includes the correct product type. |
| plugins/newspack-blocks/src/modal-checkout/modal.js | Uses new resolver/parsing helpers for URL triggers and prevents param stripping when no matching form is found. |
| plugins/newspack-blocks/src/modal-checkout/checkout-button-trigger.test.js | Adds unit tests covering trigger resolution, picker selection behavior, and safe parsing (no JSON throw). |
| plugins/newspack-blocks/src/modal-checkout/checkout-button-trigger.js | Introduces pure DOM utilities to resolve the correct form for URL-driven checkout-button triggers and copy contextual hidden fields. |
| plugins/newspack-blocks/src/blocks/checkout-button/view.php | Enqueues the modal for the variable product’s parent so the picker is available even when the button is locked to a variation. |
| plugins/newspack-blocks/includes/class-modal-checkout.php | Extends variation selection modal rendering to include variable-subscription products. |
Co-authored-by: Codex <noreply@openai.com>
Manual QA in an isolated environmentTested this branch in a fresh isolated environment (WooCommerce, Subscriptions, modal checkout) with a dedicated fixture: a variable subscription product (Monthly $10, Yearly $100) with a checkout button locked to Monthly, a plain grouped product (children $5 and $50), the Newspack donation grouped product, and a simple subscription product. Results
No One observationA Newspack auto generated grouped donation product does not open via From a QA standpoint this works as intended for the variable subscription and plain grouped cases. 🤖 Generated with Claude Code |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
All Submissions:
Changes proposed in this Pull Request:
A modal checkout link of the form
?checkout=1&type=checkout_button&product_id=NNN&variation_id=MMMnow opens the checkout modal for the requested variation. Previously these links did nothing for variable subscription and grouped products: no modal appeared, and depending on the product the URL parameters were either stripped from the address bar or left stuck there.The trigger now resolves the correct target in every configuration:
When a link requests a variation that cannot be matched to any product or picker, the checkout is no longer silently swapped for a different product. Nothing is submitted, the parameters stay in the URL, and a warning is logged so the broken link can be diagnosed. The URL-driven picker checkout also carries the source button's context (after-success behavior, content gating, popup attribution), matching a manual click. Normal clicks on checkout buttons are unchanged.
Closes NPPM-2872.
How to test the changes in this Pull Request:
These steps assume a site with Reader Activation and modal checkout enabled, WooCommerce and WooCommerce Subscriptions active, a variable subscription product with several variations, a grouped product, and a simple subscription product. Use a page with Checkout Button blocks: one linked to the variable subscription product locked to a specific variation, one linked to the grouped product, and one linked to the simple subscription product. Test logged out (or in a private window) and keep the browser console open throughout.
PAGE?checkout=1&type=checkout_button&product_id=VARIABLE_PARENT_ID(novariation_id). Confirm the modal opens for the button's locked variation and the URL parameters are cleared.PAGE?checkout=1&type=checkout_button&product_id=VARIABLE_PARENT_ID&variation_id=LOCKED_VARIATION_ID. Confirm the modal opens for that variation.variation_idset to a different variation of the same product (not the locked one). Confirm the modal opens for that other variation, and that the summary shows the requested variation rather than the locked one.PAGE?checkout=1&type=checkout_button&product_id=GROUPED_ID&variation_id=CHILD_PRODUCT_ID. Confirm the modal opens for that child product.variation_iddoes not belong to the product, for exampleproduct_id=SIMPLE_SUBSCRIPTION_ID&variation_id=UNRELATED_ID. Confirm no modal opens, the URL parameters remain in the address bar, and aNewspack modal checkout: no checkout form found...warning is logged.Uncaught SyntaxError: "undefined" is not valid JSONin the console.Other information: