1

What I am trying to achieve is this, I have configurable products I want to display the percentage of the discount as a label on the image maybe in the top right corner. I've managed to display it by using this code:

       <span>
         <?php
         $item = $block->getSaleableItem();
         $_savePercent = 100 - round(((float)$priceModel->getAmount()->getValue() / (float)$finalPriceModel->getAmount()->getValue()) * 100);
         echo '<b style="color:#008000">'.$_savePercent . '% off </b>';
        ?>
      </span>

This edit is placed in my final_price.phtml file. However with this I am displaying the % Discount in my product page as well. Because I will have different stylings for both the pages I want to display it seperatly once in the catalog and once on the product page. Is there a way to do it? I do not want to use extensions.

1 Answer 1

0

You can try https://github.com/boris1988/module-product-labels enter image description here

enter image description here

composer require bperevyazko/module-product-label bin/magento module:enable BPerevyazko_ProductLabel bin/magento setup:upgrade And configure it

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Aug 30 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.