Get Discount In Percentage of product.Magento2
Try This in List Page same way you can do it in detail page.
<?php
$specialprice = $_product->getSpecialPrice();
$specialPriceFromDate = $_product->getSpecialFromDate();
$specialPriceToDate = $_product->getSpecialToDate();
$today = time();
$price = $_product->getPrice();
if($price){ $sale = round((($price-$specialprice)/$price)*100); }
if ($specialprice) {
if ($today >= strtotime($specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime($specialPriceFromDate)&& is_null($specialPriceToDate)) { ?>
<div class="discountPrice">
<span class="sale-product-icon">
<?php if($sale) { echo $sale.'%'; } else {echo __('Sale');} ?>
</span>
</div>
<?php }
}
?>
Comments
Post a Comment