/* 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(); $_SHERPA_USER = 'USERNAME'; $_SHERPA_PASS = 'PASSWORD'; $SP = new SherpaAPI($_SHERPA_USER,$_SHERPA_PASS,true); $options = array( 'ready_at' => '2018-02-07T10:30:00+1100', ); $packages = array( array('weight'=>10), ); $vehicleType = 1; //1=Car, 2=Motorbike/scooter, 4=Van $deliveryOption = null; //null for any, 0=2 Hours, 1=4 Hours, 2=Same Day, 3=Flat Rate, 5=1 Hour $SP->setOrigin($DATA['origin']['address1'].' '.$DATA['origin']['address2'],$DATA['origin']['city'],$DATA['origin']['province'],$DATA['origin']['postal_code'],$DATA['origin']['country']); $SP->setDestination($DATA['destination']['address1'].' '.$DATA['destination']['address2'],$DATA['destination']['city'],$DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country']); $SP->setOptions($options); $r = $SP->getRate($packages,$vehicleType,$deliveryOption); 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 */ }