1

How can I set default zip code for the shipping address??

1 Answer 1

2

Create file in module app\code\Ketan\Module\etc\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="ketan_checkout_layout_processor" type="Ketan\Module\Plugin\Block\LayoutProcessor" sortOrder="1"/>
    </type>
</config>

Create Plugin file app\code\Ketan\Module\Plugin\Block\LayoutProcessor.php

<?php
namespace Ketan\Module\Plugin\Block;

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
    ) {
        $postcode = 369856;

        /*================Start For Shipping Address ===========*/

        if(isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset'])) {

            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['postcode']['value'] = $postcode;

        }

        /*================End For Shipping Address ===========*/




        /*================Start For Billing Address ===========*/
        if(isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['payments-list'])) {
            $paymentsList = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['payments-list']['children'];

            foreach ($paymentsList as $paymentCode => $payment) {
                if(strpos($paymentCode, '-form') === false) {
                    continue;
                }
                $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children'][$paymentCode]['children']['form-fields']['children']['postcode']['value'] = $postcode;
            }
        }
         if(isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'])){


            $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children']['postcode']['value'] = $postcode;

        }

        /*================End For Billing Address ===========*/
        return $jsLayout;
    }

}

Default postcode for shipping / billing address 365689

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.