Search code examples
phpmagento

Magento - Display a custom text in product page, only for products from specific categories


I need to show a text near the price for all products inside specific categories.

I've found this code that works, but it works only for one specific category. I need to put 119, 120, 121, 122 etc... more categories id, not only one.

Can you help me?

<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
            <?php if($category->getId()==119): ?>
            <span class="price-specification">
            <?php echo $this->__('Price per meter.'); ?><br />
            <?php echo $this->__('Sold only in multiples of three.'); ?>
            </span>
            <?php endif; ?>

Solution

  • To display text on more than 1 specific categories, simply do the following:

    • Create an array of all category ids in which you want to show this text. For example: $arr = array(19, 120, 121, 122);
    • Now in place of

      if($category->getId()==119):

    put the following code:

    if(in_array($category->getId(),$arr)):
    

    Please let me know if you have any question.