5

I want to disable this notice in the checkout from Magento:

Provided Zip/Postal Code seems to be invalid. Example: 1234 AB. If you believe it is the right one you can ignore this notice.

I don't want to get an notice. Just want it to be required. Can anybody help me how to do that?

I think this is special for Dutch shippingplaces.

4

Further to the answer by @Trabbie, there is a way to have a local override. The details are on the official docs but in a nutshell, create a custom extension, with a file etc/zip_codes.xml (in fact the docs currently say create etc/zip_code.xml, but that filename is incorrect.)

Then add your changes. However, there is currently a bug that means only the final <code> is used. So in the case of the Netherlands, I had to change my regex so that it made the space optional. My final zip_codes.xml looked like:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Directory:etc/zip_codes.xsd">
    <zip countryCode="NL">
        <codes>
            <code id="pattern_1" active="true" example="1234 AB">^[0-9]{4}\s?[a-zA-Z]{2}$</code>
        </codes>
    </zip>
</config>

PS. I know this isn't strictly hiding the warning as per the question, but it should reduce the chances of it being displayed!

4

This gave a bit of a headache but I have found the solution for this. The solution does not cover how to attach or disable warning messages to input fields but answers the question.

Context: Every time you change the postal code an ajax call is made and the shipping rates are recalculated. The execution will eventually enable the script located at:

vendor/magento/module-checkout/view/frontend/web/js/model/shipping-rates-validator.js

which in turn will call

vendor/magento/module-checkout/view/frontend/web/js/model/postcode-validator.js

Now depending on the result that the latter returns the shipping-rates-validator will display or not display the warning message.

as seen here:

postcodeValidation: function () {
                var countryId = $('select[name="country_id"]').val(),
                    validationResult,
                    warnMessage;

                if (postcodeElement == null || postcodeElement.value() == null) {
                    return true;
                }

                postcodeElement.warn(null);
                validationResult = postcodeValidator.validate(postcodeElement.value(), countryId);

                if (!validationResult) {
                    warnMessage = $t('Provided Zip/Postal Code seems to be invalid.');

                    if (postcodeValidator.validatedPostCodeExample.length) {
                        warnMessage += $t(' Example: ') + postcodeValidator.validatedPostCodeExample.join('; ') + '. ';
                    }
                    warnMessage += $t('If you believe it is the right one you can ignore this notice.');
                    postcodeElement.warn(warnMessage);
                }

                return validationResult;
            },

It is only logical that if the postcodeValidator(postcode-validator.js) will always return true the warn message will never be displayed.

Therefor we override the postcode-validator.js

Step 1:

Create file at [Namespace]/[Module]/view/frontend/web/js/model/postcode-validator.js with he following content:

define(['mageUtils'], function (utils) {
    'use strict';
    return {
        validatedPostCodeExample: [],
        validate: function(postCode, countryId) {
            return true;
        }
    }
});

Step 2: Map any request made to the postcode-validator to our script. Create file at [Namespace]/[Module]/view/frontend/web/requirejs-config.js with the following content:

var config = {
    map: {
        '*': {
            'Magento_Checkout/js/model/postcode-validator':'Namespace_Module/js/model/postcode-validator'
        }
    }
};

Step 3: php bin/magento cache:clean php bin/magento setup:upgrade php bin/magento setup:static-content:deploy

I don't know if this is the cleanest solution ever but does the trick. Hope this helps.

2

Just found a solution to this. You can find the zip_codes.xml in <root>vendor/magento/module-directory/etc/zip_code.xml

The Dutch postal code is defined like this (somewhere around line 319);

<zip countryCode="NL">
    <codes>
        <code id="pattern_1" active="true" example="1234 AB">^[0-9]{4}\s[a-zA-Z]{2}$</code>
    </codes>
</zip>

Now change/add;

<zip countryCode="NL">
    <codes>
        <code id="pattern_1" active="true" example="1234 AB">^[0-9]{4}\s[a-zA-Z]{2}$</code>
        <code id="pattern_2" active="true" example="1234AB">^[0-9]{4}[a-zA-Z]{2}$</code>
    </codes>
</zip>

Now customers can enter their postal code with or without a space, both are accepted without the warning. I doubt if this is upgrade-proof, I could not find a way to make it work within a child theme (like override system). But at least you get rid of the (very) annoying warning message.

2

You can disable specific zip code input mask by set "active" attribute of to false. In this specific scenario you can use following code to disable 'NL' input mask.

<zip countryCode="NL">
        <codes>
            <code id="pattern_1" active="false" example="1234 AB">^[0-9]{4}\s?[a-zA-Z]{2}$</code>
        </codes>
    </zip>

More information : http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_zip.html

2

Step-1: Go to Admin-> Store –> Configuration –> General –> Country Options here you will find an option of “Zip/Postal Code is Optional for”.

Step-2: I achieved this through css popped in the theme custom css settings or file:

[name~="shippingAddress.postcode"] > .control > .message.warning {
    display: none;
}

or Module MyCompany/MyModule/view/frontend/web/css/source/_module.less

& when(@media-common = true) {
// write here your css
    div[name$=".postcode"] {
        display: none;
    }

}

Hope does not seem to be an issue.

1

You could consider replacing the functionality with a script that validates international postal codes on entry?

I'm actually working on an extension for Magento that uses auto-suggest to speed up entry of a valid address - removing the need for that additional step you talk about where the customer is asked to double check the input. The goal is to reduce this friction for customers in the checkout process to improve conversion rates.

DISCLAIMER: I work for PCA Predict, the people behind the 'Addressy' address verification service.

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.