/* 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(); $_PRINTFUL_API = "YOUR_API_KEY"; $items = $DATA['items'] //$items is an array of lineitems, a lineitem is an array which must contain at least the following parameters: variant_id, quantity, the following are optional: price (in cents) $PF = new PrintfulAPI($_PRINTFUL_API); $PF->setDestination($DATA['destination']['address1'],$DATA['destination']['city'],$DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country']); $r = $PF->getRate($items,$e); if ($r) { foreach ($r as $_r) { $_RATES[] = array( "service_name" => $_r['name'], "service_code" => $_r['code'], "total_price" => $_r['amount']*100, //in cents "currency" => "USD", ); } } return $_RATES; /* do not edit below this line */ }