Magento itself have lot of attributes inbuilt for customers, sometimes we need to add a new attribute to customer.
So here is the code to create customer attribute in magento
In the below example we are adding “Country of Residence” as a new attribute to customer
First we need to load Mage.php

require_once 'app/Mage.php';
$installer = new Mage_Customer_Model_Entity_Setup('core_setup');
$installer->addAttribute("customer", "country_residence",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Country of Residence",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""


        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "country_residence");


        $attribute->setData("used_in_forms", $used_in_forms)
		->setData("is_used_for_customer_segment", true)
		->setData("is_system", 0)
		->setData("is_user_defined", 1)
		->setData("is_visible", 1)
		->setData("sort_order", 100)


We can see an secons section of the code in which it is used for where to display the attributes
Hope this code snippet helps you to create customer attribute in magento

Leave a Reply

Your email address will not be published. Required fields are marked *