I have the code setup to add shipping based on the subtotal. If the sub total is greater than $xx then the shipping will be $xx, If its less it will be $xx. It is easy to change to what ever you want asfar as the amount of shipping you want based on the totals.
Here is the full code
Here is the you change. No decimals are needed if you use whole numbers.<?php
$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
$strHTML = "";
if ($itemcount == 0)
{
$strHTML = "<h3>Your shopping cart is empty.</h3>";
}
else
{
$strHTML = "<div style=\"overflow:auto; height=358px;\">"."\n";
$strHTML .= "<table border=\"0\" cellpadding=\"3\" cellspacing=\"2\" width=\"100%\">"."\n";
$strHTML .= "<tr>"."\n";
$strHTML .= "<td>Product code</td>"."\n";
$strHTML .= "<td>Product name</td>"."\n";
$strHTML .= "<td>Quantity</td>"."\n";
$strHTML .= "<td>Price</td>"."\n";
$strHTML .= "<td>Total</td></tr>"."\n";
$total = 0;
$shipping = 0;
$subtotal = 0;
for ($i=0; $i<$itemcount; $i++)
{
$strHTML .= "<tr>"."\n";
$strHTML .= "<td>".$cart[PRODUCTCODE][$i]."</td>"."\n";
$strHTML .= "<td>".$cart[PRODUCTNAME][$i]."</td>"."\n";
$strHTML .= "<td><input type=\"text\" name=\"quantity".($i)."\" value=\"".$cart[QUANTITY][$i]."\" size=\"3\"></td>"."\n";
$strHTML .= "<td>"."$".number_format($cart[PRICE][$i],2)."</td>"."\n";
$strHTML .= "<td>"."$".number_format($cart[PRICE][$i]*$cart[QUANTITY][$i],2)."</td>"."\n";
$strHTML .= "</tr>"."\n";
$subtotal = $subtotal + ($cart[PRICE][$i]*$cart[QUANTITY][$i]);
}
if ($subtotal > 49.99)
{
$shipping = 3.25;
}
else
{
$shipping = 10;
}
$total = $subtotal + $shipping;
$strHTML .= "<tr>"."\n";
$strHTML .= "<td></td><td></td><td></td>"."\n";
$strHTML .= "<td>SubTotal</td>"."\n";
$strHTML .= "<td>"."$".number_format($subtotal, 2)."</td>"."\n";
$strHTML .= "</tr>"."\n";
$strHTML .= "<tr>"."\n";
$strHTML .= "<td></td><td></td><td></td>"."\n";
$strHTML .= "<td>Shipping</td>"."\n";
$strHTML .= "<td>"."$".number_format($shipping, 2)."</td>"."\n";
$strHTML .= "</tr>"."\n";
$strHTML .= "<tr>"."\n";
$strHTML .= "<td></td><td></td><td></td>"."\n";
$strHTML .= "<td>Total</td>"."\n";
$strHTML .= "<td>"."$".number_format($total, 2)."</td>"."\n";
$strHTML .= "</tr>"."\n";
$strHTML .= "</table>"."\n";
$strHTML .= "</div>"."\n";
}
echo $strHTML;
?>
You can try itif ($subtotal > 49.99)
{
$shipping = 3.25;
}
else
{
$shipping = 10;
HERE
I have tested it , but take no responsibility if it messes up