eCommerce

Add Text Before Price in Magento 1.8.1

logo_magentoSometimes it is necessary to add descriptive text in front of the price display in Magento. For instance, you may be selling something priced per unit, such as flooring by the square foot or fabric by the yard. Luckily, this is a quick and easy edit, just follow the steps below. While optimized for Magento 1.8.1, the below steps should work on earlier versions. However, line references may be slightly different:

 

1) Open app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/catalog/product/price.phtml. If you have not yet created an override file for your theme, you can copy the file from \app\design\frontend\base\default\template\catalog\product\price.phtml.

2) At line 206, locate the below block of code:

<?php else: ?>
     <span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
     <?php if ($_finalPrice == $_price): ?>
     <?php echo $_coreHelper->formatPrice($_price, true) ?>
     <?php else: ?>
          <?php echo $_coreHelper->formatPrice($_finalPrice, true) ?>
<?php endif; ?>

3) Add the below code on line 207 right below <?php else: ?>

<span class="NAME_YOUR_SPAN"><?php echo $this->__("CUSTOM TEXT") ?></span>

4) Your updated code should look like:

<?php else: ?>
     <span class="NAME_YOUR_SPAN"><?php echo $this->__("CUSTOM TEXT") ?></span>
     <span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
     <?php if ($_finalPrice == $_price): ?>
     <?php echo $_coreHelper->formatPrice($_price, true) ?>
     <?php else: ?>
          <?php echo $_coreHelper->formatPrice($_finalPrice, true) ?>
<?php endif; ?>

All done! Your custom text will be displayed before the price in both the catalog and the product pages. If you only wish to display the custom text in one location, use CSS to hide span .NAME_YOUR_SPAN in the appropriate location.

8 Comment on “Add Text Before Price in Magento 1.8.1

Leave a Reply

Your email address will not be published.