I have been working to put together a online shop for a moto x company, selling bikes, parts etc.
All is fine and working but no the client wants a delivery charge adding at the checkout using the following:
If the total price is under £50 a £5.50 delivery charge needs to be added, between £50-£100 a £10 delivery charge needs to be added and if the order is over £100 FREE delivery.
I built the shop using MySQL and PHP what would be the best and easiest way to do this.
Here's the code from my checkout page:
<?php
//connect to database
require_once('conn/db_conn.php');
mysql_select_db($database, $store);
$display_block = "<div id=\"cart\">";
//check for cart items based on user session id
$get_cart_sql = "SELECT st.id, si.item_code, si.item_price, st.sel_item_qty, st.sel_item_size, item_image, st.sel_item_color, stock_available, item_delivery FROM store_shoppertrack AS st LEFT JOIN store_items AS si ON si.id = st.sel_item_id WHERE session_id = '".$_COOKIE["PHPSESSID"]."'";
$get_cart_res = mysql_query( $get_cart_sql) or die(mysql_error());
if (mysql_num_rows($get_cart_res) < 1) {
//print message
$display_block .= "<p>You have no items in your cart.<br />
Please <a href=\"index.php\">click here</a> to continue to shop.</p>";
} else {
//get info and build cart display$total_price + $Sub_Total
while ($cart_info = mysql_fetch_array($get_cart_res)) {
$id = $cart_info['id'];
$item_title = stripslashes($cart_info['item_code']);
$item_price = $cart_info['item_price'];
$item_qty = $cart_info['sel_item_qty'];
$item_color = $cart_info['sel_item_color'];
$item_size = $cart_info['sel_item_size'];
$item_desc = $cart_info['item_desc'];
$total_price = sprintf("%.02f", $item_price * $item_qty);
$Sub_Total = sprintf("%.02f", $total_price + $Sub_Total);
$item_image = $cart_info['item_image'];
for($i=0; $i < count($get_cart_res); $i++){
$val ++;
echo "<input type='hidden' name='item_name_$val'value='".$item_title."'>";
echo "<input type='hidden' name='amount_$val'value='".$item_price."'>";
echo "<input type='hidden' name='quantity_$val'value='".$item_qty."'>";
echo "<input type='hidden' name='os1_$val' value='".$item_size."'>";
}
$display_block .= "
<div id=\"cartOrder\">
<p><img src=\"".$item_image."\"width=\"100\"\"height=\"100\"><br />
<p><?php echo $item_desc; ?></p>
Unit Price: <strong>£$item_price</strong><br />
Qty: <strong>$item_qty</strong><br />
Total Price: <strong>£$total_price</strong>
<br />
<a href=\"removefromcart.php?id=".$id."\"><img src=\"img/remove_cart.png\"border=\"0\"</a></p>
<div id=\"subtotal\">
</div>";
}
}
{
$display_block .= "
<table width=\"5px\" border=\"0\"><tr>
<td>
<th align=\"left\"bgcolor=\"#fff\" class=\"wht\"><p>Total (incl del):</p><strong><p>£$Sub_Total</p><strong><br/></th>
</td>";
$display_block .= "</table>";
}
?>
<?php echo $display_block; ?>
Help
















