I want to disable orders from a certain cities/postal-codes in Magento 2.

I want website to be accessible just visitor will not be able to order products if they are from certain cities/postal-codes.

And show Error message like "you can not order from this city."

  • "if they are from certain cities/postal-codes" and how would you do that? Based on their IP? – Julien Lachal Dec 8 '16 at 8:42
  • Based On City name or Postal code in shipping address, they provide while checkout – Arun Karnawat Dec 8 '16 at 8:49
  • So you'll let them add products to their cart, do all sorts of things, and then at checkout you'll prevent them from completing their order because they come from the wrong city? Man you'll get bad reputation for that, this is clearly a bad design. What you could do is have a banner that says orders are impossible if coming from X city or Y province. – Julien Lachal Dec 8 '16 at 9:04
  • You are right. But I have already done that Based on IP I have show a Message bellow header "Order from X City will not be fullfilled." this part is easy. Trick is how to disallow those user to complete order. because showing a Message/Banner is not enough. we need some mechanism to disable order completion. and we can not disable checkout page by checking IP as, those people still can make orders if the shipping city is anything other then X (Eg. if they want to gift). – Arun Karnawat Dec 8 '16 at 9:23

Based on your comments I can suggest 2 things, you can either:

  • intercept the call between shipping address and shipping and make a check for the city/postcode, then go back to the shipping address step and output an error
  • or you can disable the "next" button to go to shipping by default, and check the city and postcode inputs to match against an array of unauthorized values. If the fields aren't empty and the values are authorized you can then re-enable the "next" button, if not, then you can output an error message under the targeted inputs.

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.