By performing below steps one-by-one, we can put any validation in the checkout billing address.
In this example, we are going to set validation for the telephone field.
Here validation will be about the maximum and minimum length of telephone Exact ten digits going to get allowed.
First, you have to create a file in your existing module following to below path,
1 |
app\code\[VendorName]\[ModuleName]\etc\frontend\di.xml |
1 2 3 |
<type name="Magento\Checkout\Block\Checkout\LayoutProcessor"> <plugin disabled="false" name="checkout_billing_address_layoutProcessor" sortOrder="110" type="[VendorName]\[ModuleName]\Plugin\Block\Checkout\LayoutProcessor"/> </type> |
Then, you have to create another file at a given path,
1 |
app\code\[VendorName]\[ModuleName]\Plugin\Block\Checkout\LayoutProcessor.php |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php namespace [VendorName]\[ModuleName]\Plugin\Block\Checkout; class LayoutProcessor { public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, array $jsLayout) { if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payment']['children']['payments-list']['children'] )) { foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payment']['children']['payments-list']['children'] as $key => $payment) { /* Telephone Billing Address */ if (isset($payment['children']['form-fields']['children']['telephone'])) { $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payment']['children']['payments-list']['children'][$key]['children']['form-fields']['children'] ['telephone']['validation'] = ['required-entry' => true, 'min_text_length' => 10, 'max_text_length' => 10]; } } } return $jsLayout; } } |
After doing the above steps you need to run below command:
1 2 |
php bin/magento cache:flush php bin/magento cache:clean |
You can also put validations for other fields. All that you need to do is to change the field name in the form-field section. You can also change default validation error message using .csv in your module.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-628476102024f234867950/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...