Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
snippets:shipping:restricting_countries_and_states_on_the_checkout_old [2012/10/08 05:11] – Document moved from snippets:shipping:restricing_countries_and_states_on_the_checkout_old adamsnippets:shipping:restricting_countries_and_states_on_the_checkout_old [2019/01/14 00:55] (current) adam
Line 16: Line 16:
  
  
 +<WRAP center round important>
 +**Using version 2.0?** There is native functionality that covers this snippet within the configuration section of the administration. There is also a new snippet available for our latest version, [[v:2.0:snippets:locations_modfication|available from here]].
 +</WRAP>
 ====== Restricting countries from the checkout  ====== ====== Restricting countries from the checkout  ======
  
Line 63: Line 66:
   FC.checkout.setAutoComplete("shipping_state");   FC.checkout.setAutoComplete("shipping_state");
 }); });
 +</code>
 +
 +==== Restricting the country dropdown to a subset of countries ====
 +
 +Often you'll need to ship to only a few countries, like perhaps just the US and Canada. In that case, the following javascript will help you do that. Just change the ''includeCountries'' array to include the 2 character country codes of the countries you want to include.
 +
 +<code javascript>
 +<script type="text/javascript" charset="utf-8">
 +jQuery(document).ready(function(){
 +  var newCountries = [];
 +  var includeCountries = ["US", "CA"];
 +  for (var i = 0; i < FC.locations.config.locations.length; i++) {
 +    if (jQuery.inArray(FC.locations.config.locations[i].cc2, includeCountries) > -1) {
 +      newCountries.push(FC.locations.config.locations[i];
 +    }
 +  }
 +  FC.locations.config.locations = newCountries;
 +  FC.checkout.setAutoComplete("customer_country");
 +  FC.checkout.setAutoComplete("customer_state");
 +  FC.checkout.setAutoComplete("shipping_country");
 +  FC.checkout.setAutoComplete("shipping_state");
 +});
 +</script>
 </code> </code>
  
Line 89: Line 115:
     }     }
   }   }
-  var newregions = FC.locations.config.locations[usIndex].r;+  var newregions = [];
   for (var i = 0; i < FC.locations.config.locations[usIndex].r.length; i++) {   for (var i = 0; i < FC.locations.config.locations[usIndex].r.length; i++) {
-    if (FC.locations.config.locations[usIndex].r[i].c == "HI" || FC.locations.config.locations[usIndex].r[i].c == "AK") { +    if (FC.locations.config.locations[usIndex].r[i].c != "HI" && FC.locations.config.locations[usIndex].r[i].c != "AK") { 
-      newregions.splice(i,1);+      newregions.push(FC.locations.config.locations[usIndex].r[i]);
     }     }
   }   }
Line 103: Line 129:
 </script> </script>
 </code> </code>
- 
 ===== Related Forum Discussions ===== ===== Related Forum Discussions =====
  
   * http://forum.foxycart.com/comments.php?DiscussionID=1082   * http://forum.foxycart.com/comments.php?DiscussionID=1082

Site Tools