skip to Main Content

I am new to PHP and I want to apply If condition to price attribute in magento whenever Price is less than or equals to zero I want a block disappear and show when price attribute is greater than 0 then block should show up

Here is the code
If I have done any thing wrong in the code please let me know

<?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> ";
}
?>

2

Answers


  1. You have to take care of the quotes. doing it this way should better work :

    <?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; ?>
    
    Login or Signup to reply.
  2. The comments and proposed solutions are right: you have a quote issue.

    I suggest to emphasize dramatically the readability of your code as follows:

    <?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>";
      }
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search