Finally, after debugging I found the solution
The default postcode can be set by overriding the TaxConfigProvider class. To set it you have to use after plugin.
Step 1: Define plugin in 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\Tax\Model\TaxConfigProvider">
<plugin disabled="false" name="My_Module_Plugin_Frontend_Magento_Tax_Model_TaxConfigProvider" sortOrder="10" type="My\Module\Plugin\Frontend\Magento\Tax\Model\TaxConfigProvider"/>
</type>
</config>
Step 2: Create a plugin class
<?php
namespace My\Module\Plugin\Frontend\Magento\Tax\Model;
use Magento\Framework\Stdlib\CookieManagerInterface;
class TaxConfigProvider
{
/**
* @var CookieManagerInterface
*/
private $cookieManager;
/**
* TaxConfigProvider constructor.
* @param CookieManagerInterface $cookieManager
*/
public function __construct(
CookieManagerInterface $cookieManager
) {
$this->cookieManager = $cookieManager;
}
/**
* @param \Magento\Tax\Model\TaxConfigProvider $subject
* @param $result
* @return mixed
*/
public function afterGetConfig(
\Magento\Tax\Model\TaxConfigProvider $subject,
$result
) {
$result['defaultPostcode'] = $this->cookieManager->getCookie('custom_pincode');
return $result;
}
}
After implementing this code go to Store –> Configuration –> General –> Country Options here you will find an option of “Zip/Postal Code is Optional for”. Remove the country for which you want to set default zip code from this list otherwise, it will be not filled up in frontend.