Magento – Magento2 – How to add static country code in Phone Number input field

billing-addressmagento2shipping-address

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

Best Answer

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;
    }
}
Related Topic