Magento – Customer Information Attribute in New Order Email Template

customer-attributeemail-templatesmagento-1

I've scanned many posts but cannot get to bottom of this one.
I have created a custom Customer Information attribute and I need it to display on the New Order transactional email.

Any ideas? I have tried {{var customer.getAccountno()}} and a few others but it won't display.

My Code:

$installer = $this;
$installer->startSetup();


$installer->addAttribute("customer", "accountno",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Account Number",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

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


$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
        $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)
        ;
        $attribute->save();



$installer->endSetup();

Best Answer

to add the customer attribute in new order email, change the below file

Rewrite first sendNewOrderEmail() from app/code/core/Mage/Sales/Model/Order.php to your local codepool. Add $email in the template parameters.

$info = $this->getAccountno();
$mailer->setTemplateParams(array(
            'order'        => $this,
            'info'         => $info,
            'billing'      => $this->getBillingAddress(),
            'payment_html' => $paymentBlockHtml
        )
    );

Now you can access this variable like {{var info}} in the new sales order email template.

Related Topic