Reading list Switch to dark mode

    How to autofill custom address in shipping form at checkout page Magento2

    Updated 22 March 2024

    How to autofill custom address in shipping form at checkout page Magento2 : – Here i am going to explain that how to fill custom address in shipping address form at checkout page already when customer redirect this page.

    I am assuming that i have already installed magento2 dummy module.Now i will add following file in this module.

    1 –  We create di.xml file and define plugin in this file.

    create – Test/Module/di.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
            <plugin name="test_module_default_value" type="Test\Module\Plugin\Checkout\Model\Checkout\LayoutProcessor" sortOrder="100"/>
        </type>
    </config>

    2- Now Create plugin to add default value.
    create – Test/Module/Plugin/Checkout/Model/Checkout/LayoutProcessor.php

    Searching for an experienced
    Magento 2 Company ?
    Find out More
    <?php
    namespace Test\Module\Plugin\Checkout\Model\Checkout;
    
    class LayoutProcessor
    {
        /**
        * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
        * @param array $jsLayout
        * @return array
        */
        public function afterProcess(
            \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
            array  $jsLayout
        ) {
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['firstname']['value'] = 'John';
    
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['lastname']['value'] = 'Doe';
    
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['company']['value'] = 'Webkul';
    
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['city']['value'] = 'New York';
    
    
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['postcode']['value'] = '98001';
            
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset']['children']['telephone']['value'] = '1234567890';
    
    
            return $jsLayout;
        }
    }
    autofill shipping address

    Now you can check it on checkout page. Thank’s for read this.If you have any query please comment below.

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    2 comments

  • Kannan P
    • Subhangi (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home