i have this:
<?php  
       if ( ($cart->count_product) > 0) { 
           print $cart->count_product; 
       } else { 
           print ''; 
       }  
?>
and i need to put print $cart->count_product inside of <div class="my_class"></div>
I tried different ways, but i'm missing something in syntax. I'll be glad if someone could help.
You can do the following:
echo '<div class="my_class">';
echo ($cart->count_product > 0) ? $cart->count_product : '';
echo '</div>';
If you want to have it inside your statement, do this:
if($cart->count_product > 0) 
{
    echo '<div class="my_class">'.$cart->count_product.'</div>';
}
You don't need the else statement, since you're only going to output the above when it's truthy anyway.
Try this,
<?php  if ( ($cart->count_product) > 0) { ?>
         <div class="my_class"><?php print $cart->count_product; ?></div>
<?php } else { 
          print ''; 
}  ?>
                        You can do this:
<div class"my_class">
<?php if ($cart->count_product > 0) {
          print $cart->count_product; 
      } else { 
          print ''; 
      } 
?>
</div>
Before hitting the div, we are not in PHP tags
You can also do this,
<?php 
if ( ($cart->count_product) > 0) { 
  $print .= "<div class='my_class'>"
  $print .= $cart->count_product; 
  $print .= "</div>"
} else { 
   $print = ''; 
} 
echo  $print;
?>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With