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
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; ?>
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;
Buy 5 for $5.44 and save 16%
andBuy 10 for $4.87 and save 25%
?