I want to verify if the zip code entered by the customer matches correctly 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
    Commented Jul 25, 2019 at 18:52

1 Answer 1


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.

  • It is working fine. Commented Jul 29, 2019 at 11:54
  • How to show pop error message and stop to redirect to checkout page from cart page Commented Jul 29, 2019 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
    Commented Jul 29, 2019 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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