/* This macro will be parsed as PHP code (see http://www.php.net) The calculateshipping function is called every time a shipping calculation request is made by Shopify. The function must return an array of available shipping options, otherwise no shipping options will be returned to your customers. */ function calculateshipping($DATA) { /* do not edit above this line */ $_RATES = array(); $_COURIERSPLEASE_ACCOUNT = '1234567890'; // <-- replace with your own account number $_COURIERSPLEASE_KEY = '0B24C2B1C2E3D6A1B5082FB4E9B762822F1BF3959415C0'; // <-- replace with your own key $w = 0; foreach ($DATA['items'] as $i) { $w += $i['quantity']*$i['grams']/1000; } //use CM and KG $packages = array( array('length'=>10, 'width'=>10, 'height'=>5, 'weight'=>$w), ); $CPAU = new CouriersPleaseAPI($_COURIERSPLEASE_KEY,$_COURIERSPLEASE_ACCOUNT); $CPAU->setOrigin(null,$DATA['origin']['city'],null,$DATA['origin']['postal_code'],$DATA['origin']['country']); $CPAU->setDestination(null,$DATA['destination']['city'],null,$DATA['destination']['postal_code'],$DATA['destination']['country']); $r = $CPAU->getRate($packages); if ($r) { foreach ($r as $_r) { $_RATES[] = array( "service_name" => $_r['name'], "service_code" => $_r['code'], "total_price" => $_r['amount']*100, //in cents "currency" => 'AUD', ); } } return $_RATES; /* do not edit below this line */ }