我是PHP的新手,我想在价格小于或等于零的情况下在magento中应用If条件到价格属性我想要一个块消失并在价格属性大于0时显示然后块应该显示
这是代码 如果我在代码中做了任何错误,请告诉我
<?php
$Flipkart_price >0;
if ( $Flipkart_price >0 ) {
echo"
<div style="background-color:#efefef ; padding:10px"><button type="button" > <img alt="Flipkart" " class="button btn-cart" onclick="setLocation('<?php echo $_product->getStoreurl() ?>');"src="http://res.cloudinary.com/dharvdevi/image/upload/v1519810140/flipkart_store.png">
</button>
<?php echo "Price:" . $_product->getFlipkart_price(); ?>
<button type="button" title="<?php ec`enter code here`ho $buttonTitle ?>" class="button btn-cart" onclick="setLocation('<?php echo $_product->getStoreurl() ?>');">
<span><?php echo $buttonTitle ?></span></span>
</button></div> ";
}
?>
答案 0 :(得分:0)
您必须处理报价。这样做应该更好地工作:
<?php
$Flipkart_price = 1;
if ( $Flipkart_price >0 ): ?>
<div style="background-color:#efefef ; padding:10px">
<button type="button" >
<img alt="Flipkart" class="button btn-cart" onclick="setLocation('<?php echo $_product->getStoreurl() ?>');" src="http://res.cloudinary.com/dharvdevi/image/upload/v1519810140/flipkart_store.png">
</button>
<?php echo "Price:" . $_product->getFlipkart_price(); ?>
<button type="button" title="<?php echo 'enter code here' . $buttonTitle ?>" class="button btn-cart" onclick="setLocation('<?php echo $_product->getStoreurl(); ?>');">
<span><?php echo $buttonTitle; ?></span></span>
</button></div>
<?php endif; ?>
答案 1 :(得分:0)
评论和建议的解决方案是正确的:您有引用问题。
我建议大致强调代码的可读性如下:
<?php
$Flipkart_price = 1;
if ($Flipkart_price > 0) {
echo '<div style="background-color:#efefef ; padding:10px">';
echo '<button type="button">';
echo '<img alt="Flipkart" class="button btn-cart" '
. 'onclick="setLocation('
. $_product->getStoreurl()
. ');" '
. 'src="http://res.cloudinary.com/dharvdevi/'
. 'image/upload/v1519810140/flipkart_store.png">';
echo '</button>';
echo 'Price:' . $_product->getFlipkart_price();
echo '<button type="button" '
. "title=\"$buttonTitle\" "
. 'class="button btn-cart" '
. 'onclick="setLocation('
. $_product->getStoreurl()
. ');">';
echo "<span>$buttonTitle</span>"; # one </span> is enough
echo "</button></div>";
}
?>