How to verify us zip code with region in checkout and my account address magento 2.3
Вопрос
I want to verify customer enter zip code is correctly match with the region.
For example:
zip code:10001
Region: New york
If the customer enters the wrong zip code for the region, it throws an error "your zipcode and region need to match"
I think I need to use the USPS API.
I created an account in USPS API.
How to implement this functionality in the checkout page and my account save address page.
I followed this below link. But It doesn't work for me.
https://www.w3solver.com/magento-2-address-verification-using-usps-api-on-checkout/
Any help, experience and knowledge sharing would be appreciated
Решение
You have put the postcode/Region checking at
\Magento\Quote\Model\ShippingMethodManagement::estimateByExtendedAddress
\Magento\Quote\Model\ShippingMethodManagement::estimateByAddressId
because of these functions, the shipping methods are rendered at the checkout page.
Note that, Magento 2 does not save the Shipping address till database 's quote until select the Shipping method .
So, the above two methods is best way to checking ZipCode/region at checkout.