如果节省百分比高于10%,我想在产品页面上显示您的节省百分比。我使用这个代码,我发现,而搜索谷歌,但无法得到所需的结果。请帮帮我。
<?php
$_finalPrice = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice());
$_regularPrice = $this->helper('tax')->getPrice($_product, $_product->getPrice());
if ($_regularPrice != $_finalPrice):
$getpercentage = number_format($_finalPrice / $_regularPrice * 100, 2);
$finalpercentage = 100 - $getpercentage;
echo '<div class="salelabel">SAVE</br> '.number_format($finalpercentage, 0).'% </div>' ;
endif;
?>
代码看起来不错。
如果您只希望销售标签的折扣高于一定百分比,只需在其周围添加if
语句
<?php
$_finalPrice = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice());
$_regularPrice = $this->helper('tax')->getPrice($_product, $_product->getPrice());
if ($_regularPrice != $_finalPrice):
$getpercentage = number_format($_finalPrice / $_regularPrice * 100, 2);
$finalpercentage = 100 - $getpercentage;
if ($finalpercentage >= 10) {
echo '<div class="salelabel">SAVE</br> '.number_format($finalpercentage, 0).'% </div>' ;
}
endif;
?>