We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Magento has a feature to define between 1 and 4 fields, how much do you want to use in the street field?

    I’ve activated 2 fields and would like to add a label for 1 field. I have done this on the checkout shipping address page which you can see in the image below:

    I just do rewriting checkout layout on di.xml :

    <type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
        <plugin name="rewrite-street" type="VendorModuelNameModelCheckoutLayoutProcessorPlugin"/>
    </type>

    And create a new LayoutProcessorPlugin.php file at VendorModuelNameModelCheckoutLayoutProcessorPlugin.php path:

    <?php
    namespace VendorModuleNameModelCheckout;
    
    class LayoutProcessorPlugin
    {
        /**
         * @param MagentoCheckoutBlockCheckoutLayoutProcessor $subject
         * @param array $jsLayout
         * @return array
         */
    
        public function afterProcess(
            MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
            array  $jsLayout
        ) {
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['street'] = [
                'component' => 'Magento_Ui/js/form/components/group',
                'label' => __('Street Address'), // You can change main label from here
                'required' => true, //turn false if you can removed main label
                'dataScope' => 'shippingAddress.street',
                'provider' => 'checkoutProvider',
                'sortOrder' => 30, // You can set short order of street fields from other checkout fields
                'type' => 'group',
                'additionalClasses' => 'street',
                'children' => [
                    [
                        'label' => __('Label 1'), // Here I can set Label "Adresa" as per above image
                        'component' => 'Magento_Ui/js/form/element/abstract',
                        'config' => [
                            'customScope' => 'shippingAddress',
                            'template' => 'ui/form/field',
                            'elementTmpl' => 'ui/form/element/input'
                        ],
                        'dataScope' => '0',
                        'provider' => 'checkoutProvider',
                        'validation' => ['required-entry' => true, "min_text_len‌​gth" => 1], // You can also set "max_text_length"=> 255 in validation
                    ],
                    [
                        'label' => __('Label 2'),
                        'component' => 'Magento_Ui/js/form/element/abstract',
                        'config' => [
                            'customScope' => 'shippingAddress',
                            'template' => 'ui/form/field',
                            'elementTmpl' => 'ui/form/element/input'
                        ],
                        'dataScope' => '1',
                        'provider' => 'checkoutProvider',
                        'validation' => ['required-entry' => false, "min_text_len‌​gth" => 1],
                    ],
                ]
            ];
            return $jsLayout;
        }
    }

    You can do this in any existing module.

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote