In the product detail page, it's showing a discount percentage. when I open the list page it can't be showing the percentage for the configurable product.
Please give me the solution for that.
I have used the below code for that, but it's not working for the configurable product.
<div class="discount-p">
<?php
if($_product->getTypeId() == "simple") {
$simplePrice = $_product->getPrice();
} else {
$_children = $_product->getTypeInstance()->getUsedProducts($_product);
foreach ($_children as $child){
$simplePrice = $child->getPrice();
break;
}
}
$_finalPrice =$_product->getFinalPrice();
$_price = $simplePrice;
if($_finalPrice < $_price) {
$_savingPercent = 100 - round(($_finalPrice / $_price)*100);
echo '('. $_savingPercent . '%off)';
}
?>
</div>
Best Answer
You can add create saperate price file for configurable product and code within it.
add code
as it is configurable product not possible to check it by
getFinalPrice()
andgetSpecialPrice()
.add below code for configurable product.
Note : you can get this directly by change file
app\design\frontend\Vendor\theme\Magento_Catalog\templates\product\price\final_price.phtml
,you just have to put condition for configurable productpercentage will show in listing page