At first im beginner. I want to make a PHP function to calculate the discount for the pizza order. I get the data from the form.
$pizzatotal = $amount * $pizzaprice; // 4500
$realage = $currentyear - $year; //65
$cashDiscount = 2; // 2% discount if pay with cash
$yearDiscount = 3; // 3% discount if older than 60y
$payment = 1; // checkbox 1 paying with cash, 2 paying with card
I coded this function but not working fine, and i think have easiest way to calculate the discount.
echo sum($pizzatotal,$cashDiscount,$yearDiscount,$realage,$payment);
function sum($pizzatotal,$cashDiscount,$yearDiscount,$realage,$payment) {
if ($realage >='60' && $payment ='1' ) {
return $pizzatotal - ($pizzatotal * (($yearDiscount + $cashDiscount) / 100));
}
if ($realage >='60' && $payment ='2') {
return $pizzatotal - ($pizzatotal * ($yearDiscount / 100));
}
if ($realage < '60' AND $payment ='1') {
return $pizzatotal - ($pizzatotal * ($cashDiscount / 100));
}
if ($realage < '60' AND $payment ='2') {
return $pizzatotal = $pizzatotal;
}
}
Someone can help me to find other logic to make this function working good?