[Backport to release/10.6] fix: place new gateways above offline PMs in payment settings#63648
Conversation
* fix: place new gateways above offline PMs instead of at end of list (WOOPLUG-6189) When a new payment gateway is installed, place it above offline payment methods instead of at the absolute end — unless the merchant has customized the ordering. Adds is_offline_group_last() helper to detect default vs custom ordering. Fixes both Payments.php gateway loop and PaymentsProviders.php enhance_order_map() fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * changelog: add entry for WOOPLUG-6189 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: correct test expectations for new gateway placement behavior Update PaymentsProvidersTest and PaymentsTest to match the new behavior where gateways are placed above offline PMs in default ordering. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add assertNotEmpty for unused $data in PaymentsTest Address CodeRabbit review nitpick: assert on $data return value to silence static analysis warnings and add basic verification. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: align fallback placement logic between display and persistence paths Both Payments.php and PaymentsProviders.php now use Utils::order_map_add_at_order() with max()+1 for the "append at end" fallback, ensuring consistent collision handling and correct end-placement when order values have gaps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: strengthen assertions and clean up test data providers - Add assertGreaterThan for stripe > gateway1 to properly verify end-placement in custom ordering test - Remove unused $new_gateway_id parameter from test method and data provider - Replace bare strings with WC_Gateway_BACS::ID, WC_Gateway_Cheque::ID, WC_Gateway_COD::ID class constants for consistency Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: assert on final provider output instead of intermediate order map Switch both placement tests to verify $data (the sorted providers list returned to the UI) instead of the captured_order_map intermediate. This tests actual behavior rather than implementation details. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: skip suggestions in is_offline_group_last and extract shared placement method - Add is_suggestion_order_map_id() skip in is_offline_group_last() so persisted suggestion entries don't cause false negatives - Extract order_map_add_gateway() on PaymentsProviders as the single source of truth for new gateway placement logic - Both display (Payments.php) and persistence (enhance_order_map) paths now delegate to the same method - Add test cases for suggestion after offline group and missing offline group scenarios Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: oaratovskyi <oleksandr.aratovskyi@automattic.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Testing GuidelinesHi @oaratovskyi , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
This PR is a cherry-pick of #63604 to
release/10.6.Original PR Description
Submission Review Guidelines:
Changes proposed in this Pull Request:
When a new payment gateway is installed (e.g., Stripe via the NOX flow), it was being placed at the absolute bottom of the payment providers list — below offline payment methods (BACS, Cheque, COD). This meant the newly installed gateway wouldn't be expanded by default on checkout and would be buried below less commonly used methods.
This PR fixes the placement logic so that newly installed gateways are inserted above the offline payment methods group, unless the merchant has customized the provider ordering (detected by checking whether the offline group is still in its default bottom position).
Closes WOOPLUG-6189.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Milestone
Automatically assign milestone for the next WooCommerce versionChangelog entry
Automatically create a changelog entry from the details below.This Pull Request does not require a changelog entry. (Comment required below)Changelog Entry Details
Significance
Type
Message
Place newly installed payment gateways above offline payment methods instead of at the bottom of the list.
Changelog Entry Comment
Comment