---- dataentry snippet ---- type : snippet #do not change this line category : shipping #mention the category like 'shipping', 'checkout' etc name : Restricting Countries and States on the Checkout (0.7.2 and older) description : #description about snippet versions_tags : 0.6.0, 0.7.0, 0.7.1, 0.7.2 #compatible versions reference_urls : http://forum.foxycart.com/comments.php?DiscussionID=1642&page=1, http://forum.foxycart.com/comments.php?DiscussionID=2834&page=1, http://forum.foxycart.com/comments.php?DiscussionID=3482&page=1 #Comment_24000#Item_0 #Item_1 # External link tags_tags : snippets, shipping, advance #tags, separated by commas. date_dt : 2011-05-27 #the date in YYYY-MM-DD format ---- The functionality detailed on this page is for FoxyCart versions 0.7.2 and older. If you're using 1.0 or newer, please see [[restricting_countries_and_states_on_the_checkout|this page]]. **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]]. ====== Restricting countries from the checkout ====== Often times you need to alter what countries or states are able to be shipped to. The following javascript provide examples of how to do that, which need to be pasted right before the closing '''' tag of your checkout template. ==== Restricting the checkout to a single country ==== That excludes everything that is not US, but you could do it differently to adjust for the countries you want. Using firebug to analyze FC.locations.config.locations and FC.locations.config.countries will give you some idea of the structure we're using. ==== Some code for serving the US only ==== This code prevents people from altering the country text input in the checkout form - so is especially useful when you only allow customers from a single country. Simply changing ''US'' and ''United States'' to match the country you're targeting will update to your specific country. jQuery(document).ready(function() { jQuery('#customer_country, #shipping_country').val('US'); jQuery('#customer_country_name, #shipping_country_name').addClass('fc_text_readonly').val('United States'); jQuery('#customer_country_name, #shipping_country_name').attr('readonly', true).focus(function() { jQuery(this).blur(); }); // Update states FC.checkout.setAutoComplete("customer_state"); FC.checkout.setAutoComplete("shipping_state"); }); ==== 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. ===== Related Forum Discussions ===== * http://forum.foxycart.com/comments.php?DiscussionID=1642&page=1#Item_1 * http://forum.foxycart.com/comments.php?DiscussionID=2834&page=1#Item_0 * http://forum.foxycart.com/comments.php?DiscussionID=3482&page=1#Comment_24000 ====== How to remove Alaska and Hawaii from the state pulldown on checkout. ====== Often times you need to remove certain states from being selectable in your checkout. You can achieve that using javascript to run through the locations array on the checkout and removing any states you don't want. ==== Step 1: Add javascript ==== Add the following right before the closing '''' tag in your checkout template: ===== Related Forum Discussions ===== * http://forum.foxycart.com/comments.php?DiscussionID=1082