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

  • Not Working.. Here is the code that we used – Developer Account Aug 9 '18 at 7:41

  $specialprice = $_product->getSpecialPrice();
    $specialPriceFromDate = $_product->getSpecialFromDate();
    $specialPriceToDate = $_product->getSpecialToDate();    
    $today = time();
    $price = $_product->getPrice();
        $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');} ?>
        <?php }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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