I need help. I'm starting a small business website and the last thing to do before I publish is get a code for shipping. I don't know the first thing about php script codes.
I'm trying to set up shipping costs. I'm having problems with "Rule
(PHP script code) for this shipping method" I need a rule for something like $0-$25 = $7.99, $25.01-$50.00 = $10.99, $50.01-$75 = $12.99, $75.01-$100 = $14.99, $100.01-$150 = $17.99, $150.01... + = $20.00. Can you help me with a rule for this?
Any help is greatly appreciated!!!
$shipping_rates[0] = new shippingTableRate(0,25,7.99); $shipping_rates[1] = new shippingTableRate(25.01,50,10.99); $shipping_rates[2] = new shippingTableRate(50.01,75,12.99); $shipping_rates[3] = new shippingTableRate(75.01,100,14.99); $shipping_rates[4] = new shippingTableRate(100.01,150,17.99); $shipping_rates[5] = new shippingTableRate(150.01,-1,20.00); //Using -1 as upper limit to indicate infinity
function calculate_shipping($order_total) { global $shipping_rates; foreach ($shipping_rates as $a_rate) { if ($order_total >= $a_rate->from_amount && ($a_rate->to_amount == -1 || $order_total <= $a_rate->to_amount)) { return number_format($a_rate->shipping_amount,2); } } } class shippingTableRate { public $from_amount = 0; public $to_amount = 0; public $shipping_amount = 0;
function calculate_shipping($order_total) { global $shipping_rates; $array_index = floor($order_total/SHIPPING_TABLE_INCREMENT); if ((($order_total*100) % (SHIPPING_TABLE_INCREMENT*100)) == 0) { //$order_total is at upper end of range, so need to decrement $array_index by 1 $array_index--; } if ($array_index >= count($shipping_rates)) { //Take care of those that go beyond the array's end $array_index = count($shipping_rates) - 1; } return number_format($shipping_rates[$array_index],2); } echo "Shipping Cost:$".calculate_shipping(20)."<br />"; echo "Shipping Cost:$".calculate_shipping(25)."<br />"; echo "Shipping Cost:$".calculate_shipping(25.01)."<br />"; echo "Shipping Cost:$".calculate_shipping(123.67)."<br />"; echo "Shipping Cost:$".calculate_shipping(136.11)."<br />"; echo "Shipping Cost:$".calculate_shipping(270.34)."<br />"; ?>
This could should run a bit more efficiently than the previous.
AAAAHHH!!! This is making me crazy and I'm sure that I'm wasting your time. I've been working on this for three days and it's still not accepting anything that I enter. Thanks anyway.