woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
236 stars 206 forks source link

feat: For Shipping Zones Zip Regex - Correctly handle UK postcodes redacted by Apple Pay #3592

Open majikandy opened 2 weeks ago

majikandy commented 2 weeks ago

Improved upon idea in #2646 So that user does not need to add special syntax into shipping zones regex

Fixes #2645

Changes proposed in this Pull Request:

UK Postcodes consist of an outcode 2,3 or 4 characters long, then an optional space, and then 3 more characters.

Apple Pay intelligently truncates the UK postcode removing the outcode. Futhermore It keeps the optional space at the end of it's redacted string if it was there in the original.

With this behaviour known, we need to code it more intelligently when padding with stars than just assuming a UK postcode is 7 characters long.

This PR implements that behaviour.

This also enabled full support for the Regex within Shipping Zones so that Regex like

N1 * (N1 space star) correctly match postcodes like N12AA and N1 2AA to mean all N1 postcodes and correctly avoids accidental matches of N10, N11, N12 postcodes etc

This enabled proper bevaviour of shipping zones such that a user can ship to N1 for one price and N19 for another. The main scenario of this is an artistan seller/maker who will drive or walk to N1 to hand deliver, but won't to N19 without a fee (or even not at all)

Questions for the PR author:

Also the only impact of the postcode not validating is that shipping zones come up wrong due to non matches of the truncated/altered postcode. Therefore the behaviour cannot be made any worse than now.

Testing instructions

Unit tests not added as this piece of code yet as it didn't have any before - however can easily add some if this change is likely to progress into the codebase


Post merge