We need to create a new module in an existing extension. And inside that, we need to create the Setup folder and create an InstallData.php file in that folder. Inside that, we need to write the following code given below, so we can get an additional field.
<?php
namespace Fencingstore\JJ\Setup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Customer\Model\Customer;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* @var CustomerSetupFactory
*/
protected $customerSetupFactory;
/**
* @var AttributeSetFactory
*/
private $attributeSetFactory;
/**
* @param CustomerSetupFactory $customerSetupFactory
* @param AttributeSetFactory $attributeSetFactory
*/
public function __construct(
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
) {
$this->customerSetupFactory = $customerSetupFactory;
$this->attributeSetFactory = $attributeSetFactory;
}
/**
* {@inheritdoc}
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'delivery_to', [
'type' => 'varchar',
'label' => 'Delivery to',
'input' => 'select',
'required' => false,
'visible' => true,
'user_defined' => true,
'sort_order' => 160,
'position' => 162,
'system' => 0,
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
'option' => ['values' => ['Home', 'Business']],
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'delivery_to')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => [
'adminhtml_customer_address',
'adminhtml_customer',
'customer_address_edit',
'customer_register_address',
'customer_address',
]
]);
$attribute->save();
$setup->endSetup();
}
}
To see this additional field:
- we need to login into Magento admin using your username and password.
- We need to click on Customer on the left side and All customer in sub-menu

3. Then we will get all the customer’s details and we need to click on edit the as shown in the screenshot:

4. When we scroll down we can see the additional field appeared on the page:
