Right, Paypal has the same options, but doesn’t let you send the shipping options in the cart meaning you are limited to those options. Google lets you do it programatically and thus you can do anything. So SCABN uses this for Google Wallet as it is more flexible. You could, for example, offer a shipping discount when the total number of items bought is a prime number, or any other arbitrary thing you can think of.
For example:
function getShippingOptions($items) {
$totalweight=0;
$totalprice=0;
foreach($items as $item) {
$totalweight += getItemWeight($item['id'],$item['qty'],0)*$item['qty'];
$totalprice += $item['price']*$item['qty'];
}
$ship=array();
//pricearray has up-to weight as key, value as value
if ( $totalprice >= 150) {
$ship[]=array("name" => "USPS Priority Shipping (USA Only)", "price" => array(10 => 8,9999=>8), "region" => "USA");
$ship[]=array("name" => "USPS Standard Shipping (USA Only)", "price" => array(5 => 10,9999=>10), "region" => "USA");
} else {
$ship[]=array("name" => "USPS Standard Shipping (USA Only)", "price" => array(5 => 5,9999=>5), "region" => "USA");
$ship[]=array("name" => "USPS Priority Shipping (USA Only)", "price" => array(10 => 10,9999=>10), "region" => "USA");
}
$ship[]=array("name" => "USPS Express Shipping (USA Only)", "price" => array(5 => 20,9999=>30), "region" => "USA");
$ship[]=array("name" => "USPS Standard Shipping (International)", "price" => array(5 => 5,9999=>5), "region" => "NotUSA");
$ship[]=array("name" => "Global Priority (6-10 days)", "price" => array(5 => 20,9999=>30), "region" => "NotUSA");
$ship[]=array("name" => "Global Express (6 days)", "price" => array(5 => 40,9999=>60), "region" => "NotUSA" );
$availship=array();
foreach ($ship as $shipoption) {
foreach ( $shipoption['price'] as $weight => $cost ) {
if ( $totalweight <= $weight) {
$availship[]=array("name"=>$shipoption['name'],"price"=>$cost,"region"=>$shipoption['region']);
break;
}
}
}
return $availship;
}