简体   繁体   中英

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; ?>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM