Magento 2 display discount percent product page

Today we discuss how in Magento 2 display discount percent product page. This topic will cover how to show % percentage saving on current product. You can use this code on any product product listing or product widget page. You can also use this code product detail page. So let’s start with our example. You need to get $_product->getFinalPrice() and $_product->getPrice() to calculate the percentage of current product.

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

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

One thought on “Magento 2 display discount percent product page

Leave a Reply