R
R
Rolros2021-12-14 23:49:57
opencart
Rolros, 2021-12-14 23:49:57

How to discount a product in an Opencart template using PHP?

I want to manually make a 3% discount on a product and display the finished result with a 3% discount under the price in the template.
I take the $price price variable and write the code in the template:

$price = 6457;
<?php echo $price * 0.03; ?>

But the template displays some incomprehensible numbers 0.18.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2021-12-15
@Immortal_pony

First, if you run your code, the result will be 193.71, and 0.18. Check that your price contains exactly what you wrote.
Secondly, your discount formula is wrong. You calculate 3% and you need to decrease the price by 3%. For example, like this: Well, in the template later
$salePrice = $price - ($price/100*3);
<?= $salePrice ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question