Display Custom Product Attributes in Magento

So you have a Magento project that includes products with custom attributes. You need to display those attributes on the front end, but … how? It depends on the type of custom attribute. There are a number of options for custom attributes such as text field, date, price, media image and more. For many of the attributes you can use the following method.

Let’s say you have created a custom attribute for a product using the price type that you’d like to display.

First

Get your custom attribute code by logging into the admin panel.
Catalog -> Attributes -> Manage Attributes, select your custom attribute and copy the Attribute Code
For our example the custom attribute code will be example_special_price

Second

The custom attribute code needs to be modified so that it can be used by the get function in a template. Simply remove the underscores and capitalize any letter following an underscore.
For example: example_special_price becomes ExampleSpecialPrice

Third

Create the line of code with your edited attribute code that will pull in your custom attribute with the get function.

<?php echo $_product->getExampleSpecialPrice(); ?>

Place this code in your template file where you want to display the custom attribute.

That’s it!

Alternate Option

If you have an attribute that isn’t working with the normal camel case and magic-get solution you can use the getData function instead and simply pass it the unaltered custom attribute code. So for our example the custom attribute code is example_special_price so the php would look like this:

<?php echo $_product->getData('example_special_price'); ?>

Bonus Formatting

If your custom attribute is using the price type you’ll also want to use Magento’s Currency helper to create a more user friendly display. By default if the price is set in the admin to $56.00 it would display as 56.0000 on the website using the code in step 3. To change this to display as “$56.00″ simply pass your function, instead of a variable, to the currency helper like this:

<?php echo Mage::helper('core')->currency($_product->getExampleSpecialPrice(), true, false); ?>

A special thanks to Certified Magento Developer Sean Breeden for his recommendation and syntax on using the currency helper and the alternate option getData function!

For a more detailed example of displaying a drop down/multi-select check out Devin R Olsen’s post.