1 Attachment(s)
Add Customer Attribute Programmatically in Magento 2
To add the customer attribute programmatically in Magento 2, you need to follow these steps:
- Create the Setup File InstallData.ph
Quote:
<?php
namespace Company\Mymodule\Model\Source;class Customdropdown extends \Magento\Eav\Model\Entity\Attribute\Source\Abstrac tSource { public function getAllOptions() { if ($this->_options === null) { $this->_options = [ ['value' => '', 'label' => __('Please Select')], ['value' => '1', 'label' => __('Google')], ['value' => '2', 'label' => __('Friend')], ['value' => '3', 'label' => __('Email')], ['value' => '4', 'label' => __('Other')] ]; } return $this->_options; } public function getOptionText($value) { foreach ($this->getAllOptions() as $option) { if ($option['value'] == $value) { return $option['label']; } } return false; } }
For more information adding or creating customer attribute programmatically in Magento 2, visit the following blog:
Magento 2 Add Customer Attribute Programmatically