Home    Articles


How to add custom attributes to customers in magento


Here is a piece of code of code that will help you to add custom attributes to customers in magento, this is very helpful becouse magento doesn't have such thing in admin area.

Obviously you need to edit this code accordingly your needs.

You can use this piece of code anywhere in your applications/extensions...etc, you can even specify where this attribute to apear like signup page...etc.

$installer = $this;

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('customer', 'your_attribute_code_here', array(
    'input'         => 'text', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Attribute description goes here',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
    'user_defined' => 1,


$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'your_attribute_code_here');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));