I have set the discount in percentage but its showing only for the simple products.Also I want to show it in the configurable products.
For the Simple Products: vendor\magento\module-catalog\view\frontend\templates\product\view\type\default.phtml
try to set it also for
vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml
<?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="label-product label-sale">
<span class="sale-product-icon">
<?php if($sale) { echo $sale.'%'; } else {echo __('Sale');} ?>
</span>
</div>
<?php }
}
?>