0

Is it possible to display discount percentage in Magento 2.1 as referred to in the thread below? (This is for older versions)

I tried to install the "Display discount" extension from the Mage Extensions Shop, but the extension just causes my entire Configuration section to freeze. Also I spent the entire afternoon searching on Google, but nothing really helpful..

I'm on a tight schedule and working with Magento 2.1 CE.

Any suggestion is welcome!

Show product discount percent in Magento

| improve this question | | | | |
1

Modifications to certain template files will be needed to show this.

For the category view page copy /magento/module-catalog/view/frontend/templates/produc‌​t/list.phtml to your luma theme within 'Magento_Catalog/templates/product' folder. Find the section:

<?php foreach ($_productCollection as $_product): ?>

Then add below code to within this foreach loop:

if ($_product->getPrice()>$_product->getFinalPrice()):
    echo '<div class="salebox">-' . number_format((float)(1 - $_product->getSpecialPrice()/$_product->getPrice()) * 100, 0, '.', ''). '%</div>';
endif;
| improve this answer | | | | |
  • Ok, being reasonable new to Magento, where can I add this? I would like to display the discount to all products that have a special price for certain customer groups. – Douwe van der Boon Jun 15 '17 at 14:45
  • have you got a theme? – harri Jun 15 '17 at 14:52
  • I'm using the default Luma theme – Douwe van der Boon Jun 15 '17 at 14:53
  • Copy vendor/magento/module-catalog/view/frontend/templates/product/list.phtml to your luma theme within Magento_Catalog/templates/product then add that code to within the foreach loop for products. – harri Jun 15 '17 at 14:56
  • This will start you off at showing them in category pages. Product pages will be a bit more work but can add that later to my answer. – harri Jun 15 '17 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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