How can i disable/remove Zip Code for specific country in magento 2

For example if some one select UAE than Zip Code field should remove or disable else it should visible.

  • Yes, it possible , need to work some files – Amit Bera Oct 12 '17 at 7:21
  • Accept the answer If you find it helpful @Waqar – Keyur Shah Dec 13 '17 at 13:20

If you want to remove the Zip Code based on country selection, then firstly you can make zip code optional for this country from backend (i.e UAE), from store > config > general > Zip/Postal Code is Optional for and un-select your country which you want.

then you can override below javascript in your custom module


By adding


var config = {
    map: {
        '*': {
            "Magento_Ui/js/form/element/post-code": 'YOURVendor_YOURMODULE/js/form/element/post-code'

Now copy post-code into your module directory


With below javascript,

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

 * @api
], function (_, registry, Abstract) {
    'use strict';

    return Abstract.extend({
        defaults: {
            imports: {
                update: '${ $.parentName }.country_id:value'

         * @param {String} value
        update: function (value) {
            var country = registry.get(this.parentName + '.' + 'country_id'),
                options = country.indexedOptions,

            if (!value) {

            option = options[value];

            if (option['is_zipcode_optional']) { // from here custom code start 
                    // if country is optional then make it hide,
            } else {
                this.validation['required-entry'] = true;


After doing this, perform cache:flush and static-content:deploy


If you are using custom theme then you can simply copy post-code.js into your custom theme path, but this js path should be,


  • rather app/design/frontend/VENDOR/THEME/Magento_Ui/web/js/form/element/post-code.js – gnysek Jan 3 at 11:56

I have disabled the field by using jquery

first I made "zip code" field optional from admin for UAE.

then added a js file in theme Magento_Theme/layout/default_head_blocks.xml

<link src="js/disable_zip_code.js" />

then placed the js file in /web/js/disable_zip_code.js

and write the following code in js file

    require(['jquery', 'jquery/ui'], function($){ 


    $( ".country #country" ).change(function() {

      if($(this).val()=="AE" || $(this).val()=="ae" ){
        $(".zip #zip").attr("disabled","");
        $(".zip #zip").removeAttr("disabled");

    //for checkout fields

    $("body").on("change","select[name='country_id']", function(){

      if($( "[name='country_id']" ).val()=="AE" || $( "[name='country_id']" ).val()=="ae" ){



now its working

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.