0

I don't know how to implement this task.This is my task screenshot.Please check my screenshot.enter image description here

Any help will be appreciated.

1
  • do you want to get % from special price ? i.e $45 normal price and $35 is special price. ? Mar 7, 2018 at 7:26

2 Answers 2

1

add following code will give percentage saving

<?php
$_finalPrice =$_product->getFinalPrice(); 
$_price =$_product->getPrice();
if($_finalPrice < $_price):
   $_savingPercent = 100 - round(($_finalPrice / $_price)*100);
          echo $_savingPercent; ?> % Off
?>
<?php endif; ?>

If you want to add it on final_price.phtml

<?php
$_finalPrice =$block->getSaleableItem()->getFinalPrice(); 
$_price =$block->getSaleableItem()->getPrice();
if($_finalPrice < $_price):
 $_savingPercent = 100 - round(($_finalPrice / $_price)*100);
        echo $_savingPercent; ?> % Off
?>
<?php endif; ?>
13
  • Hi @ Qaisar Satti, where the code is added.Please tell me the file path.Can you please help me. Mar 7, 2018 at 8:32
  • @DileepKumar enable the template path hint from admin panel. you will find your file. you can enable through lin magento.stackexchange.com/questions/91235/… Mar 7, 2018 at 8:50
  • Hi @ Qaisar Satti, this code is not working.It generates this below error message.We're sorry, an error has occurred while generating this email. Can you please help me. Mar 7, 2018 at 9:24
  • Hi @ Qaisar Satti,I have added the code path is C:\xampp7.0\htdocs\magento2\vendor\magento\module-catalog\view\base\templates\product\price\final_price.phtml file.It is correct?Can you please help me? Mar 7, 2018 at 9:26
  • @DileepKumar check the latest code. Mar 7, 2018 at 9:32
0

could you pls advice which is correct place to add your piece of code? I'm a bit confused because it has no php opening block like <?php if but have closing one...

Your Answer

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

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