0

I created a table in the price box to display the quantity and discount percentage. I would like to also show the discounted price in this table.

For example, if the product price is $100

display discount price

1
  • Similar to Buy 5 for $5.44 and save 16% and Buy 10 for $4.87 and save 25%?
    – Bojjaiah
    Commented Sep 3 at 11:52

2 Answers 2

1

I believe you were using Tier pricing which offers a quantity discount to members of a specific customer group and website.

To add the table structure to display the quantity, discount percentage, and savings in price.phtml. For example:

<?php
// Get the current product object
$product = $_product; // $_product is the current product object passed in the context

// Get the product price
$basePrice = $product->getPrice();

// Get the tier prices
$tierPrices = $product->getTierPrices();

if (!empty($tierPrices)) : ?>
    <table>
        <thead>
            <tr>
                <th>QTY</th>
                <th>Discount</th>
                <th>Save</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($tierPrices as $tierPrice) :
                $tierQty = $tierPrice->getQty();
                $tierPriceValue = $tierPrice->getPrice();
                $discountPercentage = (($basePrice - $tierPriceValue) / $basePrice) * 100;
                $savings = ($basePrice - $tierPriceValue) * $tierQty;
            ?>
            <tr>
                <td><?php echo (int)$tierQty; ?></td>
                <td><?php echo number_format($discountPercentage, 2); ?>%</td>
                <td><?php echo '$' . number_format($savings, 2); ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php endif; ?>
0

I tried this code and it worked perfectly

$Discountpercentage = intval($block->formatPercent($tierPriceModel->getSavePercent($price['price'])));
$regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getValue();
$numproduct = $price['price_qty'];
$totaldiscount = number_format((($regularPrice/100)$Discountpercentage)$numproduct,0); echo $totaldiscount;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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