ASHTools

This is a helper class for ASH-based / enabled Shipping plugins.

Defined (1)

The class is defined in the following location(s).

/wpsc-includes/shipping.helper.php  
  1. class ASHTools { 
  2. /** 
  3. * Determines if the given zipcode is a US Military APO/AFO zip code 
  4. * @since 0.0.1 
  5. * @param int $zipcode 
  6. * @return boolean 
  7. */ 
  8. function is_military_zip($zipcode) { 
  9. $zips = array("09302", "09734", "96201", "96202", "96203", "96204", "96205", "96206", "96206", "96207",  
  10. "96208", "96212", "96213", "96214", "96215", "96217", "96218", "96219", "96220", "96221",  
  11. "96224", "96251", "96257", "96258", "96259", "96260", "96262", "96264", "96266", "96267",  
  12. "96269", "96271", "96275", "96276", "96278", "96283", "96284", "96297", "96306", "96309",  
  13. "96309", "96310", "96311", "96311", "96313", "96319", "96321", "96322", "96323", "96326",  
  14. "96328", "96330", "96336", "96337", "96338", "96339", "96339", "96343", "96347", "96348",  
  15. "96349", "96350", "96351", "96351", "96362", "96365", "96367", "96368", "96370", "96372",  
  16. "96373", "96374", "96375", "96376", "96377", "96378", "96379", "96384", "96386", "96387",  
  17. "96388", "96388", "96401", "96402", "96403", "96404", "96424", "96425", "96426", "96427",  
  18. "96490", "96507", "96507", "96511", "96515", "96515", "96517", "96517",  
  19. "96518", "96520", "96520", "96521", "96522", "96530", "96531", "96531", "96534", "96535",  
  20. "96536", "96537", "96538", "96540", "96541", "96542", "96543", "96544", "96546", "96548",  
  21. "96549", "96550", "96551", "96553", "96554", "96555", "96557", "96557", "96595", "96595",  
  22. "96598", "96599", "96601", "96602", "96603", "96604", "96605", "96606", "96607", "96608",  
  23. "96609", "96610", "96611", "96612", "96613", "96613", "96614", "96614", "96615", "96615",  
  24. "96616", "96616", "96617", "96617", "96619", "96619", "96620", "96620", "96621", "96622",  
  25. "96623", "96624", "96628", "96629", "96634", "96635", "96643", "96657", "96657", "96660",  
  26. "96661", "96662", "96663", "96664", "96665", "96666", "96667", "96668", "96669", "96670",  
  27. "96671", "96672", "96673", "96674", "96675", "96677", "96678", "96679", "96681", "96681",  
  28. "96682", "96683", "96684", "96684", "96686", "96687", "96698"); 
  29.  
  30. return in_array( $zipcode, $zips ); 
  31.  
  32. /** 
  33. * Given an ISO country code, it will return the full country name 
  34. * @since 0.0.1 
  35. * @param string $short_country 
  36. * @return string 
  37. */ 
  38. function get_full_country( $short_country ) { 
  39. $country = new WPSC_Country( $short_country ); 
  40. return $country->get_name(); 
  41.  
  42. /** 
  43. * Given a WPEC state code (int), will return the state/region name 
  44. * @since 0.0.1 
  45. * @param int $state_code 
  46. * @return string|int will be int if wordpress database & wpec are not available 
  47. */ 
  48. function get_state( $state_code ) { 
  49. $state_code = isset( $_POST['region'] ) ? $_POST['region'] : $state_code; 
  50. return wpsc_get_region( $state_code ); 
  51.  
  52. /** 
  53. * Retrieves value for given key from $_POST or given session variable 
  54. * You need to provide the session stub b/c it doenst know where you are looking 
  55. * @since 0.0.1 
  56. * @param mixed $key 
  57. * @param array $session 
  58. * @return mixed 
  59. */ 
  60. function post_or_session($key, $session) { 
  61. if (array_key_exists($key, $_POST)) { 
  62. return $_POST[$key]; 
  63. }elseif(array_key_exists($key, $session)) { 
  64. return $session[$key]; 
  65.  
  66. /** 
  67. * Retrieves the destination from session or post as an array 
  68. * or "state", "country", and "zipcode" 
  69. * @since 0.0.1 
  70. * @param array $session 
  71. * @return array 
  72. */ 
  73. function get_destination($session) { 
  74. $address = array("state"=>$this->get_state($this->post_or_session("region", $session)),  
  75. "country"=>$this->post_or_session("country", $session),  
  76. "zipcode"=>$this->post_or_session("zipcode", $session) 
  77. ); 
  78. return $address; 
  79.  
  80. /** 
  81. * Checks if the destination country requires a postal code 
  82. * @since 3.8.14 
  83. * @param string $iso_code 
  84. * @return bool 
  85. */ 
  86. function needs_post_code( $iso_code ) { 
  87.  
  88. $no_post_code = array(); 
  89.  
  90. $no_post_code['AO'] = "Angola"; 
  91. $no_post_code['AG'] = "Antigua and Barbuda"; 
  92. $no_post_code['AW'] = "Aruba"; 
  93. $no_post_code['BS'] = "Bahamas"; 
  94. $no_post_code['BZ'] = "Belize"; 
  95. $no_post_code['BJ'] = "Benin"; 
  96. $no_post_code['BQ'] = "Bonaire, Sint Eustatius and Saba"; 
  97. $no_post_code['BW'] = "Botswana"; 
  98. $no_post_code['BF'] = "Burkina Faso"; 
  99. $no_post_code['BI'] = "Burundi"; 
  100. $no_post_code['CM'] = "Cameroon"; 
  101. $no_post_code['CF'] = "Central African Republic"; 
  102. $no_post_code['KM'] = "Comoros"; 
  103. $no_post_code['CG'] = "Congo (Brazzaville)"; 
  104. $no_post_code['CD'] = "Congo, Democratic Republic"; 
  105. $no_post_code['CK'] = "Cook Islands"; 
  106. $no_post_code['CI'] = "Cte d'Ivoire (Ivory Coast)"; 
  107. $no_post_code['CW'] = "Curaao"; 
  108. $no_post_code['DJ'] = "Djibouti"; 
  109. $no_post_code['DM'] = "Dominica"; 
  110. $no_post_code['TL'] = "East Timor"; 
  111. $no_post_code['GQ'] = "Equatorial Guinea"; 
  112. $no_post_code['ER'] = "Eritrea"; 
  113. $no_post_code['FJ'] = "Fiji"; 
  114. $no_post_code['TF'] = "French Southern and Antarctic Territories"; 
  115. $no_post_code['GM'] = "Gambia"; 
  116. $no_post_code['GH'] = "Ghana"; 
  117. $no_post_code['GD'] = "Grenada"; 
  118. $no_post_code['GN'] = "Guinea"; 
  119. $no_post_code['GY'] = "Guyana"; 
  120. $no_post_code['HK'] = "Hong Kong"; 
  121. $no_post_code['IE'] = "Ireland"; 
  122. $no_post_code['JM'] = "Jamaica"; 
  123. $no_post_code['KI'] = "Kiribati"; 
  124. $no_post_code['KP'] = "Korea, North"; 
  125. $no_post_code['MO'] = "Macau"; 
  126. $no_post_code['MW'] = "Malawi"; 
  127. $no_post_code['ML'] = "Mali"; 
  128. $no_post_code['MR'] = "Mauritania"; 
  129. $no_post_code['MU'] = "Mauritius"; 
  130. $no_post_code['MS'] = "Montserrat"; 
  131. $no_post_code['NR'] = "Nauru"; 
  132. $no_post_code['NU'] = "Niue"; 
  133. $no_post_code['QA'] = "Qatar"; 
  134. $no_post_code['KN'] = "Saint Kitts and Nevis"; 
  135. $no_post_code['LC'] = "Saint Lucia"; 
  136. $no_post_code['ST'] = "Sao Tome and Principe"; 
  137. $no_post_code['SC'] = "Seychelles"; 
  138. $no_post_code['SX'] = "Sint Maarten"; 
  139. $no_post_code['SL'] = "Sierra Leone"; 
  140. $no_post_code['SB'] = "Solomon Islands"; 
  141. $no_post_code['SO'] = "Somalia"; 
  142. $no_post_code['SR'] = "Suriname"; 
  143. $no_post_code['SY'] = "Syria"; 
  144. $no_post_code['TZ'] = "Tanzania"; 
  145. $no_post_code['TG'] = "Togo"; 
  146. $no_post_code['TK'] = "Tokelau"; 
  147. $no_post_code['TO'] = "Tonga"; 
  148. $no_post_code['TV'] = "Tuvalu"; 
  149. $no_post_code['UG'] = "Uganda"; 
  150. $no_post_code['AE'] = "United Arab Emirates"; 
  151. $no_post_code['VU'] = "Vanuatu"; 
  152. $no_post_code['YE'] = "Yemen"; 
  153. $no_post_code['ZW'] = "Zimbabwe"; 
  154.  
  155. return apply_filters( 'wpsc_ash_tools_needs_post_code', ( ! isset( $no_post_code[ $iso_code ] ) ), $no_post_code, $iso_code );