Have a moment to answer a few questions? We'd love your feedback on working with FoxyCart templates: Click here for more information
Shipping Only US but Bill to Address can be International
  • dgasserdgasser
    Member
    I have successfully blocked out all international shipping outside the US but I've just been informed we can accept payment from outside the US but only deliver in the US. I'm trying to figure out the code so at CheckOut, if someone enters a NON US BILLING address the SHIP TO check box is automatically checked and they have to enter in a US shipping address or it will fail.

    This is what I have so far so I'm guessing it will be an alteration of it with additions:
    <script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function(){
    jQuery('#customer_country, #shipping_country').val('US');
    jQuery('#customer_country_name, #shipping_country_name').val('United States');
    jQuery('#customer_country_name, #shipping_country_name').attr('readonly', true).focus(function() {
    this.blur();
    });
    });
    </script>
  • fc_adamfc_adam
    FoxyCart Team
    @dgasser,

    So this one had me intrigued so I have a stab at it and have come up with the following. Brett or Luke may come along and say that there is a much more foxy approach to this, but this is what I could come up with. Basically it checks the customer country field and acts accordingly. It also overrides the function that the checkbox calls as be default when you click that checkbox it replaces the shipping country with the billing country, so I had to overwrite that to allow it to stay as 'United States'. Just paste it in the head of your checkout template.
    <script type="text/javascript" charset="utf-8">
    	  //<![CDATA[
        jQuery(document).ready(function() {
          jQuery('#shipping_country').val('US');
          jQuery('#shipping_country_name').val('United States');
          jQuery('#shipping_country_name').attr('readonly', 'readonly').focus(function() {
            this.blur();
          });
          jQuery("#customer_country_name").change(function() {
            validateBillingCountry();
          });
     
          function validateBillingCountry() {
            if(jQuery("#customer_country_name").val() != "United States") {
              jQuery("#use_different_addresses").click().attr("disabled", "disabled");
              if ($("#shippingAlert").length == 0) {
                jQuery("#fc_use_different_address label span").append("<h4 id='shippingAlert'>Shipping only available to United States</h4>");
              }
            } else {
              jQuery("#shippingAlert").remove();
              jQuery("#use_different_addresses").removeAttr("disabled").click();
            }
          }
     
      	  displayShippingAddress = function (obj) {
        		jQuery("#shipping_service_id").val("0");
        		if (obj.checked) {
        			jQuery("#fc_address_shipping_container").show();
        		} else {
        			jQuery("#fc_address_shipping_container").hide();
        		}
      			FC.checkout.updateShipping(-1);
      			FC.checkout.updateTaxes(-1);
        	}
     
        	FC.checkout.displayShippingAddress = displayShippingAddress;
          validateBillingCountry(this);
        })
    	  //]]>
    	</script>

    Important note: This code overwrites some default code from FoxyCart so proceed with caution and Test, Test, Test.
  • Ok... I don't know what to say but.. WOW!! Let me give it a try and see how it works. Thank you so much Adam..
  • So I set up an Test Account (thanks for the suggestion Brett) to test this and It partially works. The "YOUR SHIPPING ADDRESS" is locked to US only, but there is one small issue.

    The "USE A DIFFERENT SHIPPING ADDRESS" doesn't seem to lock when entering the Billing information which has NON-US address. It come up right away having the "USE A DIFFERENT SHIPPING ADDRESS" checked but it can be easily un-checked after entering the information. I'll whisper my test account to you. All I've done is use the default shopping cart and added the addition.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>^^store_name^^ Checkout</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="https://^^store_domain^^/themes/standard/styles.css" type="text/css" media="screen" charset="utf-8" />
    <script type="text/javascript" charset="utf-8">
    //<![CDATA[[/color]
    jQuery(document).ready(function() {
    jQuery('#shipping_country').val('US');
    jQuery('#shipping_country_name').val('United States');
    jQuery('#shipping_country_name').attr('readonly', 'readonly').focus(function() {
    this.blur();
    });
    jQuery("#customer_country_name").change(function() {
    validateBillingCountry();
    });

    function validateBillingCountry() {
    if(jQuery("#customer_country_name").val() != "United States") {
    jQuery("#use_different_addresses").click().attr("disabled", "disabled");
    if ($("#shippingAlert").length == 0) {
    jQuery("#fc_use_different_address label span").append("<h4 id='shippingAlert'>Shipping only available to United States</h4>");
    }
    } else {
    jQuery("#shippingAlert").remove();
    jQuery("#use_different_addresses").removeAttr("disabled").click();
    }
    }

    displayShippingAddress = function (obj) {
    jQuery("#shipping_service_id").val("0");
    if (obj.checked) {
    jQuery("#fc_address_shipping_container").show();
    } else {
    jQuery("#fc_address_shipping_container").hide();
    }
    FC.checkout.updateShipping(-1);
    FC.checkout.updateTaxes(-1);
    }

    FC.checkout.displayShippingAddress = displayShippingAddress;
    validateBillingCountry(this);
    })
    //]]>
    </script>
    </head>

    <body id="checkout">
    <div id="pageContainer" style="width:760px; margin:0px auto;">
    ^^cart^^
    ^^checkout^^
    </div>
    </body>
    </html>
  • I was using iE and then went back to Firefox and it works for Firefox but NOT IE... eeks. I cleared my cache and in iE and still not working correctly. I'll play around with it a bit with IE.

    There is a small problem with Firefox too. If the Billing addressed is changed immediately from US to another Country the "USE A DIFFERENT SHIPPING ADDRESS" is not click able.
  • fc_adamfc_adam
    FoxyCart Team
    @dgasser, its working for me (even in your test account you whispered) in Firefox and IE 8 and 6. What version of IE are you using?
  • Really? It does seem strange on my side. I'm using the latest for Firefox and IE 8. Odd.. I even deleted all cookies and cache...everything.

    What is even more strange is I don't get that special "Ship to only US" in IE 8 at all and in Firefox I get it.
  • I've downloaded Google Chrome and tried that and having same problems as Firefox.
    1. Type in E-mail address
    2. Change Billing to Canada (Shipping disappears)
    3. Can't click on checkbox to Ship to US address.
  • Now I've tried using this in Safari and it's acting just like IE 8.. This is so weird. So this is what I have so far:

    FireFox / Chrome / SeaMonkey / Opera. Change Billing address to (Canada), Shipping portion disappears and can't click on "USE DIFFERENT SHIPPING ADDRESS".. I can see the special statement. As soon as I put a US Country in Billing I can click on the box.
    '
    Safari & IE 8 . Change change Billing address to (UK) but still can click on "USE DIFFERENT SHIPPING ADDRESS". Strange thing is special notice does not come up.

    This is ODD! Seems like it handles Java differently possibly. I wish I can take a video of this and send it to you. I thought it was me but I've tried 6 different browsers.
  • fc_adamfc_adam
    FoxyCart Team
    Ah yep, I can replicate some of that :)

    Replace the validateBillingCountry function in your code with the following and let me know how you go:
    function validateBillingCountry() {
    if(jQuery("#customer_country_name").val() != "United States") {
    jQuery("#use_different_addresses").attr({checked: 'checked', disabled: 'disabled'});
    displayShippingAddress(jQuery("#use_different_addresses").get(0));
    if ($("#shippingAlert").length == 0) {
    jQuery("#fc_use_different_address label span").append("<h4 id='shippingAlert'>Shipping only available to United States</h4>");
    }
    } else {
    jQuery("#shippingAlert").remove();
    jQuery("#use_different_addresses").removeAttr("disabled");
    jQuery("#use_different_addresses").removeAttr("checked");
    displayShippingAddress(jQuery("#use_different_addresses").get(0);
    }
    }
  • Tried replacing the "validatebillingCountry" and this seem to have not change or effect as the first code. It's as thought I'm just using the Standard Foxycart Checkout.
  • fc_adamfc_adam
    FoxyCart Team
    @dgasser, well thats the problem with not properly testing the code before I post it :) 1 missing ")"!
    function validateBillingCountry() {
    if(jQuery("#customer_country_name").val() != "United States") {
    jQuery("#use_different_addresses").attr({checked: 'checked', disabled: 'disabled'});
    displayShippingAddress(jQuery("#use_different_addresses").get(0));
    if ($("#shippingAlert").length == 0) {
    jQuery("#fc_use_different_address label span").append("<h4 id='shippingAlert'>Shipping only available to United States</h4>");
    }
    } else {
    jQuery("#shippingAlert").remove();
    jQuery("#use_different_addresses").removeAttr("disabled");
    jQuery("#use_different_addresses").removeAttr("checked");
    displayShippingAddress(jQuery("#use_different_addresses").get(0));
    }
    }

    There's one bug with this code that I've just discovered, in that it doesn't quite work if a country is selected from the autocomplete dropdown via a mouse click. I'll take a closer look and get back to you on that one
  • Hi Adam,

    I tried this out and it seems to be working in Firefox, even the drop down, but doesn't seem to be working with IE8. It's strange I don't get the little warning about shipping only to the US when using Explorer.

    We are so close!!
  • fc_adamfc_adam
    FoxyCart Team
    @dgasser,

    So the way I was doing it before (setting an onchange on the country) was breaking a lot of other stuff. I think I've found an approach that works, but it's probably even more unsupported than my previous code :) I can't replicate what you're seeing in IE8 with the old code or the new code. Give this a try though and see if it magically fixes it :)

    http://pastie.org/private/climkx1sqanasvdwrwqpw
  • Adam,

    Looks like the code provided with the link above is working on all the browsers NOW!!!! I'm going to do some more testing before implementing it into production. I should have a final test tonight.

    Why would this code be "unsupported"?
  • brettbrett
    FoxyCart Team
    Because all this custom stuff that we do for users isn't part of the FoxyCart core, and as such we can't promise it will work either now or in the future. For all the stuff that's built into FoxyCart we test, test, test, and still find issues. For something like this that's a quick one-off to meet the specific need of a user, we only test briefly but expect you to do as much testing as you feel is necessary.

    Also, as we upgrade our system in future versions, we test against what's in the FoxyCart core, but not against every custom javascript implementation.

    So that's why it's "unsupported". We LOVE helping like this, and we're super lucky to have Adam on the team now to take over a lot of this more advanced custom stuff, but ultimately we can't do it for everybody, and we have to be clear about what it is, how it's been tested, and such.

    Does that help?

    We're really glad it's working now though ;)
  • Thanks Brett,

    That is completely understandable and reasonable. Adam did a fantastic job on this. Thanks for all of your help.. If it was capable, the first round would be on me.
  • fc_adamfc_adam
    FoxyCart Team
    @dgasser, glad its working for you mate :)
  • We'll I found a BUG which I'm trying to attempt to fix and it's a HUGE problem. The Receipt and the Transactions are not showing me the Shipping address at all. So I don't know where to ship items to now.. It's something with the additional Java Script in the Checkout. When getting the the Receipt it Drops all the Shipping Information.
  • I've done some major testing on what is going on and for some reason the Script is killing all the information of the Shipping Info on the Receipt. I've tried just loading the small script into the TEXT CHECKOUT and used TEXT for CART and RECEIPT and no luck... Darn it!... just when I thought we had it.!

    Any thoughts on why this java script is kill the Shipping information? I'll that is coming back is:

    Shipping Information
    Shipping Method: Flat Rate Shipping .


    here is the html
    <DIV class="fc_inner">
    <OL id="fc_receipt_shipping_list">
    <LI class="fc_row fc_shipping_service">
    <SPAN class="fc_pre">Shipping Method<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">Flat Rate Shipping</SPAN>
    </LI>
    </OL>
    <SPAN class="fc_clear"> </SPAN>
    </DIV>


    It suppose to come back looking like this:
    <DIV class="fc_inner">
    <OL id="fc_receipt_shipping_list">
    <LI class="fc_row fc_shipping_service">
    <SPAN class="fc_pre">Shipping Method<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">Flat Rate Shipping</SPAN>
    </LI>
    <LI class="fc_row fc_shipping_first_name">
    <SPAN class="fc_pre">First Name<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">dfad</SPAN>
    </LI>
    <LI class="fc_row fc_shipping_last_name">
    <SPAN class="fc_pre">Last Name<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">gasd</SPAN>
    </LI>
    <LI class="fc_row fc_shipping_address1">
    <SPAN class="fc_pre">Address 1<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">aasdfasdf</SPAN>
    </LI>
    <LI class="fc_row fc_shipping_city">
    <SPAN class="fc_pre">City<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">afa</SPAN>
    </LI>
    <LI class="fc_row fc_shipping_state">
    <SPAN class="fc_pre">State / Province<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">WI</SPAN>
    </LI>
    <LI class="fc_row fc_shipping_postal_code">
    <SPAN class="fc_pre">Postal Code<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">13414</SPAN>
    </LI>
    <LI class="fc_row fc_shipping_country">
    <SPAN class="fc_pre">Country<SPAN class="fc_colon">:</SPAN></SPAN> <SPAN class="fc_text">US</SPAN>
    </LI>
    </OL>
    <SPAN class="fc_clear"> </SPAN>
    </DIV>
  • lukeluke
    FoxyCart Team
    Sorry for the frustration dgasser. This is one of the reasons we tend to shy away from developing custom JavaScript hacks and would prefer to focus on core functionality. Because the use_different_addresses field was removed and/or disabled, it looks like that bit is not being sent to the checkout process so FoxyCart doesn't know to collect that shipping information and save it. By default, if that check box is checked, that data will be saved. Because you're wanting to do something custom, we can't be sure of the results. You may be able to inject a hidden input tag into the form with the right id and name of use_different_addresses which may help, but I'm not familiar enough with this customization to be sure. Maybe Adam has some additional input. If you need us to recommend a developer for you to continue with this customization, please let us know.
  • I had to take the code out and put in a disclaimer and leave it up to the customer to check out correctly.
  • fc_adamfc_adam
    FoxyCart Team
    Well that's interesting, and definately why we recommend testing whenever you step away from default functionality! One approach you could take is when a shipping address is required to hide the use_different_address checkbox using css, and replace it with a dummy checkbox that is disabled. That way the information would still be passed through to checkout, and people can still see that its required.
  • I don't want hide the use_different_address checkbox ... I almost want to have the Shipping address always show. I don't understand why this would effect the SHIPPING part of the Receipt. If the data is being entered into the field it has to be capture and kept somewhere. It's been 3 days now with no success getting this to work. I have to rely on the customer to do the correct thing and that makes me a bit worried.
  • lukeluke
    FoxyCart Team
    Did fc_adam's solution make sense? You're customizing core functionality and in doing so it's breaking things, so it's a little difficult for us to conceive of every possible outcome of making these changes. You said you don't want that checkbox but the system is built on that being a checkbox and (on the backend) a value being posted to the page to determine whether or not the data in the shipping fields should be used or not. If that value isn't sent to the system either as a checkbox or a hidden input with the same value, the backend will think the checkbox was not checked and the data is ignored. That may not seem obvious, but there's more going on behind the scenes (such as GEO ip targeting of the shipping country) that require us to respect that value from the checkbox and make decisions based on it.

    If fc_adam's solution won't work or doesn't make sense we can recommend some developers who can help further, just let us know and we'll send you a list.
  • fc_adamfc_adam
    FoxyCart Team
    Just to show you how this would look in a basic form, i've modified the script to hide the checkbox if shipping is required, but mark it as checked so the shipping information is displayed and required, and should also be displayed on the receipt. Obviously, test this out before proceeding with it, I didn't test my changes.

    http://pastie.org/private/gcrsg60lqxzfymmuepbila
  • Hi Luke & Adam,

    I've been away for a few days, sorry in the delayed response. I'll Test the changes and see how it works. Thanks for your time and patience with this. If all else fails I'll just leave what I have in place.
  • My first initial test and this seems to work great. I'll Whisper a test site to you if you want to try it out.
  • Ok... I finished the TESTING and it works for anything outside the US. BUT.... If I have a US Billing Address and want to ship to another US Mailing address the address does not appear.

    Is there anyway just to have the customer fill out both Shipping and Billing Address not matter what (locking the shipping address to US).
  • lukeluke
    FoxyCart Team
    hey dgasser. This thread is getting a bit long and it sounds like you still haven't gotten the support you need for the customization you want. Would you like us to recommend a list of developers who've worked quite a bit with FoxyCart and might be able to help you out? We do what we can in the forums, but if it's not a standard feature or a bug, we generally recommend an outside developer so that we can stay focused on core functionality that everyone needs while you still get the excellent service you expect.
  • Hi Luke.. Sure can you send me the information. I'm going to take a stab at it myself for a bit and if I can't get it to work I'll look into developer.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion