/* 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(); if ($DATA['destination']['country'] != 'GB') return array(); //zones $zones = array( 'A' => array( 'area' => array('AL','B1','B2','B3','B4','B5','B6','B7','B8','B9','BA','BB','BD','BH','BL','BN','BR','BS','CA','CB','CF','CH','CM','CO','CR','CT','CV','CW','DA','DD','DE','DG','DH','DL','DN','DT','DY','E1','E2','E3','E4','E5','E6','E7','E8','E9','EC','EH','EN','EX','FY','G','GL','GU','HA','HD','HG','HP','HR','HU','HX','IG','IP','KT','KY','L1','L2','L3','L4','L5','L6','L7','L8','L9','LA','LD','LE','LL','LN','LS','LU','M1','M2','M3','M4','M5','M6','M7','M8','M9','ME','MK','ML','N1','N2','N3','N4','N5','N6','N7','N8','N9','NE','NG','NN','NP','NR','NW','OL','OX','PE','PL','PR','RG','RH','RM','S1','S2','S3','S4','S5','S6','S7','S8','S9','SA','SE','SG','SK','SL','SM','SN','SO','SP','SR','SS','ST','SW','SY','TA','TD','TF','TN','TQ','TS','TW','UB','W1','W2','W3','W4','W5','W6','W7','W8','W9','WA','WC','WD','WF','WN','WR','WS','WV','YO','PO1','PO2','PO3','PO4','PO5','PO6','PO7','PO8','PO9','PO10','PO11','PO12','PO13','PO14','PO15','PO16','PO17','PO18','PO19','PO20','PO21','PO22','AB10','AB11','AB12','AB13','AB14','AB15','AB16','AB21','AB22','AB23','AB24','AB25','AB30','AB31','AB32','AB33','AB34','AB35','AB36','AB39','FK1','FK2','FK3','FK4','FK5','FK6','FK7','FK8','FK9','FK10','FK11','FK12','FK13','FK14','FK15','FK16','FK17','FK18','KA1','KA2','KA3','KA4','KA5','KA6','KA7','KA8','KA9','KA10','KA11','KA12','KA13','KA14','KA15','KA16','KA17','KA18','KA19','KA20','KA21','KA22','KA23','KA24','KA25','KA26','KA29','KA30','PA1','PA2','PA3','PA4','PA5','PA6','PA7','PA8','PA9','PA10','PA11','PA12','PA13','PA14','PA15','PA16','PA17','PA18','PA19','PH1','PH2','PH3','PH4','PH5','PH6','PH7','PH8','PH9','PH10','PH11','PH12','PH13','PH14','TR1','TR2','TR3','TR4','TR5','TR6','TR7','TR8','TR9','TR10','TR11','TR12','TR13','TR14','TR15','TR16','TR17','TR18 TR19','TR20','TR21','TR26','TR27'), 'options' => array( 'Standard Shipping' => 5.95, 'Express Shipping' => 11.50, ), ), 'B' => array( 'area' => array('IV1','IV2','IV3','IV4','IV5','IV6','IV7','IV8','IV9','IV10','IV11','IV12','IV13','IV14','IV15','IV16','IV17','IV18','IV19','IV20','IV21','IV22','IV23','IV24','IV25','IV26','IV27','IV28','IV29','IV30','IV31','IV32','IV33','IV34','IV35','IV36','IV37','IV38','IV39','IV40','IV63','AB37','AB38','AB41','AB42','AB43','AB44','AB45','AB51','AB52','AB53','AB54','AB55','AB56','FK19','FK20','FK21','KA27','KA28','PA20','PA21','PA22','PA23','PA24','PA25','PA26','PA27','PA28','PA29','PA30','PA31','PA32','PA33','PA34','PA35','PA36','PA37','PA38','PH15','PH16','PH17','PH18','PH19','PH20','PH21','PH22','PH23','PH24','PH25','PH26','PH30','PH31','PH32','PH33','PH34','PH35','PH36','PH37','PH38','PH39','PH40','PH41','PH42','PH43','PH44','PH49','PH50','KW1','KW2','KW3','KW4','KW5','KW6','KW7','KW8','KW9','KW10','KW11','KW12','KW13','KW14'), 'options' => array( 'Scottish Highlands' => 12.75, ), ), 'C' => array( 'area' => array('IV41','IV42','IV43','IV44','IV45','IV46','IV47','IV48','IV49','IV50','IV51','IV52','IV53','IV54','IV55','IV56','PA20','PA41','PA42','PA43','PA44','PA45','PA46','PA47','PA48','PA49','PA60','PA61','PA62','PA63','PA64','PA65','PA66','PA67','PA68','PA69','PA70','PA71','PA72','PA73','PA74','PA75','PA76','PA77','PA78','PA80','KW15','KW16','KW17'), 'options' => array( 'Scottish Islands' => 21.50, ), ), 'D' => array( 'area' => array('BT'), 'options' => array( 'Northern Ireland 3 Day Service' => 13.50, ), ), 'E' => array( 'area' => array('PO30','PO31','PO32','PO33','PO34','PO35','PO36','PO37','PO38','PO39','PO40','PO41'), 'options' => array( 'Isle of Wight Overnight by 5pm' => 15.95, ), ), 'F' => array( 'area' => array('ZE','HS','TR22','TR23','TR24','TR25'), 'options' => array( 'Offshore Delivery Service' => 22.50, ), ), ); //parse postcode $postcode = trim(str_replace(' ','',strtoupper($DATA['destination']['postal_code']))); if (preg_match('/^([A-Z]+)(.+?)[0-9][A-Z]{2}$/',$postcode,$m)) { $area = $m[1]; $district = $m[2]; } //find zone $matchedRates = null; foreach ($zones as $zone => $z) { if (in_array($area.$district,$z['area'])) { //matched on area and district $matchedRates = $z['options']; break; } else if (in_array($area,$z['area'])) { //matched only on area $matchedRates = $z['options']; break; } } if ($matchedRates !== null) { foreach ($matchedRates as $ratename => $rate) { if ($rate === null) continue; $_RATES[] = array( "service_name" => $ratename, //this is what the customer will see "service_code" => $ratename, //can be anything you like "total_price" => ($rate)*100, //in cents "currency" => "GBP", ); } } return $_RATES; /* do not edit below this line */ }