Maybe someone can help me over this opportunity. I am trying to get the results of several functions to add up at the end of my checkout page. I am losing the values somewhere and am getting a 0.00 for the results of some simple addition. Besides spending a few more hours in the manual, does anyone have a suggestion to correct what is probably a simple error that my brain has missed?
function calculate_shipping($total_weight,$ship_method,$total_price)
{
if ($total_price >= 1000.00) { return 0.00; }
else
if ($total_weight <= "10" and $ship_method == "UPS_Ground") { return 7.00; }
if ($total_weight <= "10" and $ship_method == "UPS_Overnight") { return 14.00; }
if ($total_weight >= "10" and $ship_method == "UPS_Ground") { return 30.00; }
if ($total_weight >= "10" and $ship_method == "UPS_Overnight") { return 60.00; }
}
This function is called by the following:
//calculate the shipping costs
display_shipping(calculate_shipping($total_weight,$ship_method,$total_price));
Which displays the shipping on a separate line on a check out page. Here is the code that displays the shipping cost table.
function display_total_amt($shipping,$tax,$total_price)
{
// display table row with shipping cost, tax
?>
<table border = 0 width = 100% cellspacing = 0>
<tr><th bgcolor="#cccccc" align = left>TOTAL ORDER AMOUNT</th>
<th bgcolor="#cccccc" align = right>$<?=number_format($shipping, 2) ?></th>
</tr>
</table>
<?
}
A similar function and display produces the tax to be charged.
The table that is to display the total added values is below.
function display_total_amt($shipping,$tax,$total_price)
{
// display table row with total price reflecting the added tax and shipping.
?>
global $total_price;
?>
<table border = 0 width = 100% cellspacing = 0>
<tr><th bgcolor="#cccccc" align = left>TOTAL INCLUDING SHIPPING</th>
<th bgcolor="#cccccc" align = right>$<?=number_format($shipping+$tax+$total_price, 2); ?></th>
</tr>
</table>
<?
}
This is my problem. Although the values of $tax and $shipping display on their respective lines, their value is lost as soon as the function call is completed. Thus the ($shipping+$tax+$total_price, 2); returns a 0.00 result. How do I convert the value of the function calculate_shipping result to a variable value that can be used in other parts of the application?
I know I am missing something really simple here.