-2

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> ";
}
?>
Teemu
  • 22,918
  • 7
  • 53
  • 106
  • 1
    http://php.net/manual/en/function.echo.php – Teemu Mar 11 '18 at 09:10
  • 1
    You cannot use un-escaped quotes in a quote – Nico Haase Mar 11 '18 at 09:11
  • 2
    You're using double quotes for `echo "...` to print your html, well your html has another double-quote in it at `
    – Jason Spradlin Mar 11 '18 at 09:12
  • 1
    You code has too many errors. My suggestion : Please understand at least the basics of PHP before writing codes. The first comment will take you to the documentation for PHP `echo` function but I think you should also read other PHP functions and understand the standard syntax. – Rajan Benipuri Mar 11 '18 at 09:14

2 Answers2

0

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; ?>
kevinniel
  • 1,088
  • 1
  • 6
  • 14
0

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>";
  }
?>
Pierre François
  • 5,850
  • 1
  • 17
  • 38
  • First of All thanks for your quick response. I have tried your code it works but If the price is 0 still div is showing up at the front end but it suppose to disappear How can we do that? – Jiyan Devi Mar 11 '18 at 13:11
  • If you set `$Flipkart_price = 1;` just before `if ($Flipkart_price > 0)`, the test will never fail. Adapt this part of the code. – Pierre François Mar 11 '18 at 15:11