since I'm new to PHP I have a quite simple question. After Googling and searching here on stackoverflow I still can't get it to work.
<?php
$payinfront = $product->get_price_html();
$totalprice = $payinfront * 2;
?>
<p class="price">Total price: <?php echo $totalprice ?></p>
<p class="price">Amount to pay in front: <?php echo $payinfront ?></p>
<p class="price">Amount to pay after: <?php echo $totalprice - $payinfront ?></p>
The $payinfront value does get it's value from another part of my template. Let's say it's €10,-. This is the amount people have to pay in front. When we have done the service they have to pay the other half wich is the last rule.
Thanks for helping me out!
You want to store prices as floats, not as strings, so that PHP can recognize them as numeric values, and do calculations on them. Only cast them to strings at the very last moment, when you are
echo
ing them in your template.Then, when you
echo
the prices, you might want to format them in a certain way, usingnumber_format()
:You first have to remove the euro sign so that the variable can be considered a number. Then you make the multiplication and concatenate the euro sign below at the html part.
Like this?
Note that
€
makes an euro signRemove the currency symbol before multiplication: