For magento 2 the below code will work to create separate entry for billing and shipping.
i am skipping to module create basic step. here is the direct required changes to fulfill the requirement.
First create the di file on the below location.
app/code/[Vendor]/[Module_Name]/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\Customer\Model\Address">
<plugin name="after_customer_save" type="[Vendor]\[Module_Name]\Plugin\Model\CustomerAfterSave" sortOrder="10"/>
</type>
</config>
After declaration plugin need to create plugin class in directory.
app/code/[Vendor]/[Module_Name]/Plugin/Model/CustomerAfterSave.php
<?php
namespace [Vendor]\[Module_Name]\Plugin\Model;
use Magento\Customer\Model\AddressFactory;
use Psr\Log\LoggerInterface;
class CustomerAfterSave
{
const SHIPPING_ADDRESS_COUNT = '1';
/**
* Construct function
*
* @param AddressFactory $address
* @param LoggerInterface $logger
*/
public function __construct(
AddressFactory $address,
LoggerInterface $logger
) {
$this->addressModel = $address;
$this->logger = $logger;
}
/**
* Create New address after magento address saved
*
* @param \Magento\Customer\Model\Address $subject
* @param string $savedAddress
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @return mixed
*/
public function afterSave(
\Magento\Customer\Model\Address $subject,
$savedAddress
) {
$customer = $savedAddress->getCustomer();
if (is_object($customer) &&
$customer->getDefaultBilling() ==
$customer->getDefaultShipping() &&
$customer->getAddressesCollection()->getSize() <= self::SHIPPING_ADDRESS_COUNT
) {
$this->customerAddressSaveAfter($savedAddress);
}
return $savedAddress;
}
/**
* Create new default shipping address
*
* @param \Magento\Customer\Model\Address $address
* @return this
*/
private function customerAddressSaveAfter($address)
{
try {
if ($address->getIsDuplicate()) {
return $this;
}
$oriAddress = $this->addressModel->create()->load($address->getId());
$oriAddress->setIsDefaultShipping(true)
->setIsDuplicate(true)
->__clone();
$oriAddress->save();
} catch (\Exception $e) {
$this->logger->critical($e->getMessage());
}
return $this;
}
}