/* 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(); $DATA = enrichCartDetails($DATA,false,0); print_r($DATA); //WARNING: discount coupon detection may not always function correctly, read the user guide for limitations. $discountCodes = array('YOUR DISCOUNT CODE','ANOTHER DISCOUNT CODE'); $hasCode = false; if (isset($DATA['cart']['discount_codes'])) { foreach ($DATA['cart']['discount_codes'] as $discount) { if (in_array(strtoupper($discount['code']),$discountCodes)) $hasCode = true; } } if ($hasCode) { $_RATES[] = array( "service_name" => 'Discounted Shipping', "service_code" => 'Discounted Shipping', "total_price" => 1000, "currency" => "USD", ); } else { $_RATES[] = array( "service_name" => 'Retail Shipping', "service_code" => 'Retail Shipping', "total_price" => 0, "currency" => "USD", ); } return $_RATES; /* do not edit below this line */ }