Code for Magento Product Type

In the Magento templates you’ll often want to code different actions or markup for individual product types. First of course, you have to target those product types using PHP and here’s how.

Update: 04 September 2014
!Important Note: some Magento files or Magento themes will use $_product instead of $product. Be sure to check the .phtml file you are working in to see which version of the product object the file is using and use that one. So if an example below says ‘$product’ but your .phtml file uses ‘$_product’ edit the code snippet below to use ‘$_product’.

Simple Product

<?php if($product->getTypeId() == "simple"): ?>
//Your Code Here
<?php endif; ?>

Grouped Product

<?php if($product->getTypeId() == "grouped"): ?>
//Your Code Here
<?php endif; ?>

Configurable Product

<?php if($product->getTypeId() == "configurable"): ?>
//Your Code Here
<?php endif; ?>

Bundle Product

<?php if($product->getTypeId() == "bundle"): ?>
//Your Code Here
<?php endif; ?>

Virtual Product

<?php if($product->getTypeId() == "virtual"): ?>
//Your Code Here
<?php endif; ?>

Or if you want to code for all other product types except for a certain product type you would use this code.

All Non-Simple Product

<?php if($product->getTypeId() != "simple"): ?>
//Your Code Here
<?php endif; ?>

All Non-Grouped Product

<?php if($product->getTypeId() != "grouped"): ?>
//Your Code Here
<?php endif; ?>

All Non-Configurable Product

<?php if($product->getTypeId() != "configurable"): ?>
//Your Code Here
<?php endif; ?>

All Non-Bundle Product

<?php if($product->getTypeId() != "bundle"): ?>
//Your Code Here
<?php endif; ?>

All Non-Virtual Product

<?php if($product->getTypeId() != "virtual"): ?>
//Your Code Here
<?php endif; ?>