-1

I got this error from my product.tpl, inserted some codes to manipulate my price and stocks, im looking to end my code using this } absolutely but i got no luck.

<?php if($price == "₱0.00" && $stock == "In Stock" ) { ?><?php echo "Customizable"; ?>
<?php } else { ?>
<?php if($price == "₱0.00" && $stock == "For inquiry") { ?><?php echo "For inquiry"; ?>
<?php } else { ?>
<?php if($price) { ?><?php echo $price; ?></h4>
<?php } ?>

Originally the code is this and i added to a little bit of code to the highlighted code

<ul class="list-unstyled">
<?php if (!$special) { ?>
<li>
<h4><?php if($price) { ?><?php echo $price; ?></h4>
</li>
<?php } else { ?>
<li><span style="text-decoration: line-through;"><?php echo $price; ?>
</span>
<h4><?php echo $special; ?></h4></li>             
<?php } ?>
<?php if ($tax) { ?>
<li><?php echo $text_tax; ?><?php echo $tax; ?></li>
<?php } ?>
<?php if ($points) { ?>
<li><?php echo $text_points; ?> <?php echo $points; ?></li>
<?php } ?>
<?php if ($discounts) { ?>
<?php foreach ($discounts as $discount) { ?>
<li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?>
<?php echo $discount['price']; ?></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
France
  • 9
  • 8

3 Answers3

0

The if elseif is used like below:

<?php if($condition) { //action } elseif($condition2) { //action2 } ?>

I think you want this:

<ul class="list-unstyled">
    <?php if(!$special) { ?>
        <li>
            <h4><?php echo $price; ?></h4>
        </li>
    <?php }else{ ?>
        <li>
            <span style="text-decoration: line-through;"><?php echo $price; ?></span>
            <h4><?php echo $special; ?></h4>
        </li>
        <?php if($tax) { echo '<li>'.$text_tax.$tax.'</li>';} ?>
        <?php if($points) { echo '<li>'.$text_points.$points.'</li>';} ?>
        <?php 
            if($discounts){
                foreach ($discounts as $discount) {
                    echo '<li>'.$discount["quantity"].$text_discount'<br>'.$discount['price'].'</li>';
                }
            }
        ?>
    <?php } ?>
</ul>
Mahmoud Kassem
  • 409
  • 5
  • 9
0

Formatting your code properly really helps. Does the code below work the way you want it to?

<?php if(!$special) { ?>
<ul class="list-unstyled">
    <li>
    <?php if($price == "₱0.00" && $stock == "In Stock" ) {
        echo "Customizable";
    } else if($price == "₱0.00" && $stock == "For inquiry") {
        echo "For inquiry";
    } else if($price) { ?>
        <h4><?=$price;?></h4>
    <?php } else { ?>
        <span style="text-decoration: line-through;"><?=$price;?></span>
        <h4><?=$special;?></h4>
    <?php } ?>
    </li>
<?php if($tax) { ?>
    <li><?=$text_tax.' '.$tax;?></li>
<?php } ?>
<?php if($points) { ?>
    <li><?=$text_points.' '.$points;?></li>
<?php } ?>
<?php if(count($discounts)) { foreach ($discounts as $discount) { ?>
    <li><?=$discount['quantity'].' '.$text_discount.' '.$discount['price'];?></li>
<?php } } ?>
</ul>
<?php } ?>
Pyromonk
  • 684
  • 1
  • 12
  • 27
  • syntax error, unexpected line 142 – France Apr 24 '17 at 01:10
  • i added the original code to my post – France Apr 24 '17 at 01:23
  • @France, my suggestion still remains the same: please format your code in such a way that _you_ can read it. I had to rewrite your code from scratch. I'd also recommend not having `h4` tags inside `li` tags. Anyway, please check if my solution works for your needs. – Pyromonk Apr 24 '17 at 01:49
  • dude this is working but i want the echo displayed by

    because it is equivalent to my price

    – France Apr 24 '17 at 02:13
  • @France, I am pleased to hear that. All I'm saying is that having block elements inside inline elements is against html standards. It's your project, so it's up to you if you want to follow them or not. – Pyromonk Apr 24 '17 at 03:12
0

Use proper format, too many tags of php, use codes look like this.

<?php
    if($price == "₱0.00" && $stock == "In Stock" ) {
        echo "Customizable";
    } else if($price == "₱0.00" && $stock == "For inquiry") {
        echo "For inquiry";
    } else if($price) {
        echo $price;
    }
?>
Jrey
  • 1,618
  • 2
  • 17
  • 34