我有价格表,每月和每年的费用,但我需要一个免费访问的价格表。如果我将价格设置为零,我会得到一个错误,因为代码无法读取零价格。在代码段下方。谢谢
<?php foreach ($Packages->getDataAs("Package") as $p): ?>
<div class="price">
<div class="price-content">
<div class="main-price">
<h1><?= format_price($p->get("monthly_price")) ?></h1>
<p><?= htmlchars($Settings->get("data.currency")) ?>/<?= __("per month") ?></p>
</div>
<p class="special-discount">
<?php
$total = 12 * $p->get("monthly_price");
$dif = $total - $p->get("annual_price");
$save = $dif * 100 / $total;
if ($save > 0) {
echo __("Save %s when paid annualy", format_price($dif) . " " . htmlchars($Settings->get("data.currency")));
}
?>
</p>
添加此项将解决您的问题
$total = 12 * $p->get("monthly_price");
$dif = $total - $p->get("annual_price");
if($total > 0) //Omits Divide by zero exception
$save = $dif * 100 / $total;
else
$save = 0;