Create a custom order attribute in Magento

I’ve run into a few posts about this thing but none of them was working out of the box so I took all the info and glued them together so…

if you’ve to create a custom attribute for a Magento order but you don’t have a module (and its installer script) simply create a php file in the project’s root with this code:

require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute  = array(
        'type'          => 'text',
        'backend_type'  => 'text',
        'frontend_input' => 'text',
        'is_user_defined' => true,
        'label'         => 'Your attribute label',
        'visible'       => true,
        'required'      => false,
        'user_defined'  => false,   
        'searchable'    => false,
        'filterable'    => false,
        'comparable'    => false,
        'default'       => ''
);
$installer->addAttribute('order', 'your_attribute_code', $attribute);
$installer->endSetup();

This attribute is a “text” and it’s made not to be visible but just to use it as a container for some data you may need in your custom development, more info may come in comments if you need.

4 thoughts on “Create a custom order attribute in Magento

  1. martin

    nice tutorial
    too much time was lost too find the best solution for my problems with customers attributes.
    i read much information about magento and some modifications.
    but one day my old friend advise me a great solution for me.
    he advised me amasty’s extension customer attributes. and it is really works perfect.
    your are free to read about that extension

    you can ask some questions about extension to amasty.

  2. Asad

    How do we add a date attribute in checkout and registration page? As I sell perishable products and its important to get the exact delivery date and time.
    We were also considering some extensions for this purpose, I found one here –
    Can you recommend a development solution or some other extension?

Leave a Reply

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