3

I have only one country in country dropdown and I want to add static country code in Phone Number field in shipping and billing address in checkout.

How Can I add this in checkout shipping and billing address?

enter image description here

Question Updated:

I want to add a div before phone number field to manage the static country code like this:- enter image description here

1 Answer 1

0

You can show the value using below code in,

/app/code/Vendor/Module/etc/frontend/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="ProcessReferrerConfiguration" type="Vendor\Module\Plugin\Block\Checkout\LayoutProcessor"/>
    </type>
</config>

app/code/Vendor/Module/Plugin/Block/Checkout/LayoutProcessor.php

<?php

namespace Vendor\Module\Plugin\Block\Checkout;

class LayoutProcessor
{

    /**
     * Checkout LayoutProcessor after process plugin.
     *
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $processor
     * @param array $jsLayout
     * @return array
     */
    public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $processor, $jsLayout)
    {
        $jsLayout['components']['checkout']['children']['steps']
        ['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['telephone']['value'] = '+91';
        return $jsLayout;
    }
}
6
  • Is it tested? because I am not able to get desired result Commented Feb 28, 2020 at 8:44
  • Try my updated answer..Remove checkout_index_index.xml
    – aravind
    Commented Feb 28, 2020 at 9:08
  • Not working , Please also review My updated question Commented Feb 28, 2020 at 9:25
  • My updated answer is working one. I have tested, but it will be displayed directly inside telephone number field and not in separate box.
    – aravind
    Commented Feb 28, 2020 at 9:28
  • I need in separate box So I set this with css before Phone number field Commented Feb 28, 2020 at 9:30

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.