0

How to add a new field to this section and save DB: enter image description here

Please help me.

baovic
  • 1
  • 3

1 Answers1

0

To create an customer address attribute you need to create a module, I am assuming that you know hot create a module in Magento2. If not please follow some blogs or this links or this

after creating module, you can use this code in your InstallData or UpgradeData

use Magento\Customer\Setup\CustomerSetupFactory;

  /**
     * Customer setup factory
     *
     * @var CustomerSetupFactory
     */
    private $customerSetupFactory;

    /**
     * Init
     *
     * @param CustomerSetupFactory $customerSetupFactory
     */
    public function __construct(CustomerSetupFactory $customerSetupFactory)
    {
        $this->customerSetupFactory = $customerSetupFactory;
    }

Now you can use this like,

/**
 * {@inheritdoc}
 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
 */
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    /** @var CustomerSetup $customerSetup */
    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

    $setup->startSetup();


    $attributesInfo = [
        'YOUR_ATTRIBUTE)ID' => [
            'label' => 'YOUR ATTRIBUTE LABEL',
            'type' => 'static',
            'input' => 'text',
            'position' => 140,
            'visible' => true,
            'required' => false,
        ]
    ];

    foreach ($attributesInfo as $attributeCode => $attributeParams) {
        $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);
    }
    $setup->endSetup();
}
Keyur Shah
  • 18,046
  • 6
  • 66
  • 80