Fix taxes endpoint not returning multiple postcodes/cities #27751
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
The proposed changes allow the
taxesendpoint to return an array of postcodes/cities for tax rates with multiple (semi-colon separated) postcodes and/or cities in two new keys,citiesandpostcodes; the old existingcityandpostcodekeys are kept for compatibility and will return only one of the available values.Closes #27750 .
How to test the changes in this Pull Request:
In WooCommerce admin go to Settings - Tax - Standard Rates and create 3 rates: one with no cities or postcodes specified, another one with one city and one postcode, and one with two cities and two postcodes (separate them with a semicolon,
;).Temporarily add this at the ned of your woocommerce.php file, this way you won't have to bother about REST API authentication:
add_filter('woocommerce_rest_check_permissions', function() {return true;}, 10, 0 );(note that this will cause a bunch of unit tests to fail)Retrieve the taxes via the
/wp-json/wc/v3/taxesendpoint and verity that the results are consistent:For no city and no postcode:
{ "postcode": "", "city": "", "postcodes": [], "cities": [] }For one city and postcode:
{ "postcode": "1111", "city": "OSAKA", "postcodes": [ "1111" ], "cities": [ "OSAKA" ], }For two cities and postcodes:
{ "postcode": "2222", "city": "KOBE", "postcodes": [ "1111", "2222" ], "cities": [ "OSAKA", "KOBE" ],Other information:
Changelog entry