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.


Any help, experience and knowledge sharing would be appreciated

  • This is module is not good for your requirement – Amit Bera Jul 25 '19 at 18:52

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.

| improve this answer | |
  • It is working fine. – Arunprabakaran M Jul 29 '19 at 11:54
  • How to show pop error message and stop to redirect to checkout page from cart page – Arunprabakaran M Jul 29 '19 at 11:55
  • If you want to show this message at pop then you have work more and logic will different from current. – Amit Bera Jul 29 '19 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.