/* 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(); $_API_KEY = 'YOUR API KEY'; $s = new StallionExpressAPI($_API_KEY); $s->setDestination($DATA['destination']['address1'],$DATA['destination']['address2'],$DATA['destination']['city'],$DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country']); $packages = array( array('weight'=>10, 'length'=>8, 'width'=>5.25, 'height'=>3.125, 'signature'=>false, 'value'=>10, 'insure'=>false), ); $packageType = 'legal_flat_rate_envelope'; //valid values: parcel, legal_flat_rate_envelope, flat_rate_padded_envelope, small_flat_rate_box, medium_flat_rate_box_1, medium_flat_rate_box_2, large_flat_rate_box, regional_rate_box_a1, regional_rate_box_a2, regional_rate_box_b1, regional_rate_box_b2, letter, large_envelope_or_flat, thick_envelope $packageContents = 'shoes'; //description of the items $r = $s->getRate($packages,$packageType,$packageContents,'METRIC'); if ($r) { foreach ($r as $_r) { $_RATES[] = array( "service_name" => $_r['name'].($_r['businessdays']!=''?" ({$_r['businessdays']} Business days)":''), "service_code" => $_r['code'], "total_price" => $_r['amount']*100, //in cents "currency" => "USD", ); } } return $_RATES; /* do not edit below this line */ }