Magento – Magento 2: Post Code isn’t being validated as ‘required’ on Checkout

checkoutform-validationmagento2validation

On my theme, the customer is allowed to proceed to the payment page of the checkout without having to add a Postcode, despite it being set as required. The other fields (Street, City) are required and validate correctly when they're left empty (the user is prevented from proceeding to the next step).

Any ideas why this is the case?

Best Answer

On the checkout page, by default, the Postal Code are required field.

vendor/magento/module-checkout/view/frontend/layout/checkout_index_index.xml

<item name="postcode" xsi:type="array">
    <!-- post-code field has custom UI component -->
    <item name="component" xsi:type="string">Magento_Ui/js/form/element/post-code</item>
    <item name="validation" xsi:type="array">
        <item name="required-entry" xsi:type="string">true</item>
    </item>
</item>

enter image description here

So, you should check this field in your custom layout. Make sure the Required validation is enabled.

Additionally, if you want to make this attribute to be required on the server side also, you can use a simple query to :

UPDATE eav_attribute a SET a.`is_required` = 1 WHERE a.`attribute_code` = 'postcode';