-3

I get this message in my browser: Parse error: syntax error, unexpected 'if' (T_IF)

I have been making a HTML table showing prices on a Woocommerce product.

I have seen a lot of similar issues, but cannot relate to my own problem.

The problem should be in this code...

            <tr>
                <td>'. $product_variation->get_name() .'</td>
                <td>'. $product_variation->get_regular_price() .'</td>
                <td>'
                 if($sale_price) {
                   echo $sale_price;
                    }else {
                   echo $product_variation->get_regular_price();
                    }
                '</td>
            </tr>';´´´
  • 1
    I'm sure you already figure it out. The answer is in the error message: "syntax error". This is how you embed PHP code in HTML: `` – kodeart Jul 04 '19 at 17:26
  • I've done this a lot of times before, and also know the method you mention. The problem is just that the code construction is different and therefore gets the error. – Søren Jessen Jul 05 '19 at 07:32

1 Answers1

0

use php Tags around this:-

<?php
if($sale_price) {
  echo $sale_price;
}else {
echo $product_variation->get_regular_price();
}
?>
Mohit Kumar
  • 952
  • 2
  • 7
  • 18