Skip to content

Checkout fields priority refactor#21763

Merged
claudiulodro merged 6 commits intomasterfrom
fix/checkout-field-priority
Oct 31, 2018
Merged

Checkout fields priority refactor#21763
claudiulodro merged 6 commits intomasterfrom
fix/checkout-field-priority

Conversation

@kloon
Copy link
Copy Markdown
Contributor

@kloon kloon commented Oct 31, 2018

All Submissions:

Changes proposed in this Pull Request:

In #20640 it was reported that the trigger to mimic a country select was causing issue, it was then removed which broke the field priority on intial page load. #21733 added back an onselect trigger without knowing it will cause #20640 to happen again.

This PR removes the onselect trigger again and goes with another approach by sorting via PHP, thanks @pierrebuet for the suggestion and idea based on the code you provided. I reworked Pierre's code a bit as it was not working on all the filters you can use to change the checkout fields and also refactored the other uasort methods we have by introducing a new wc_uasort_comparison method which can be reused.

Closes #21642

How to test the changes in this Pull Request:

  1. Use either the woocommerce_checkout_fields or the woocommerce_default_address_fields or any of the other filters you can use to alter the checkout fields and changes the priority of one of the fields to 1 so it should show right at the top of the checkout page.
  2. Load the checkout page and ensure the field is displayed at the correct place based on the priority set.

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?

Changelog entry

Fix - Checkout field priority was not applying on initial page load.

@kloon kloon added this to the 3.5.1 milestone Oct 31, 2018
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 31, 2018

Codecov Report

Merging #21763 into master will decrease coverage by <.01%.
The diff coverage is 71.43%.

Impacted Files Coverage Δ Complexity Δ
includes/class-wc-checkout.php 1.5% <0%> (-0.01%) 212 <0> (+1)
includes/wc-core-functions.php 52.57% <100%> (+0.14%) 0 <0> (ø) ⬇️
includes/class-wc-tax.php 79.78% <0%> (-0.27%) 130% <0%> (ø)

Copy link
Copy Markdown
Contributor

@claudiulodro claudiulodro left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks for adding a unit test to prove it works. 👍

@claudiulodro claudiulodro merged commit 696e22f into master Oct 31, 2018
@claudiulodro claudiulodro deleted the fix/checkout-field-priority branch October 31, 2018 16:11
@masato-igarashi
Copy link
Copy Markdown

hi
thanks for fix issue in checkout page.
but this issue still occurred v3.5.1 in "my account > edit addresses" page.
(my-account/edit-address/billing/)

@pierrebuet
Copy link
Copy Markdown
Contributor

@masato-igarashi : I confirm, the edit addresses page doesn't sort the fields the way it should. In my original commit, the sorting happens at the source, in the class WC_Countries. The edited commit sorts the fields on the checkout page only. So now the sorting should be done also on the edit pages - or basically each time address fields are requested - too or at the source only once as I suggested.

@kloon
Copy link
Copy Markdown
Contributor Author

kloon commented Nov 7, 2018

Cannot do at the source as there are multiple filters in place that can change the fields after the source, we need to accommodate those as well. Working on a fix for the My Account pages.

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.

5 participants