Supporting country pre-population on v2.0 Checkout?

pixelchutespixelchutes Member
in Bugs & Feature Requests edited October 2015
According to https://wiki.foxycart.com/v/2.0/cheat_sheet#customer_information_pre-population
pre-populating the country isn't supported
...is that because it interferes with the geo IP / auto select logic?

Is there a possible work-around using hidden fields to get the country value to use a predetermined value? I know this kind of unofficial approach was possible back on v0.6.0, I'm just curious if there's something specific that needs accounting for on v2.0 that would prevent the desired outcome with some custom code?

e.g.

FC.client.on('ready', function () {
// Country pre-pop workaround
if( typeof FC.json.custom_fields.country != 'undefined' ){
if( FC.json.custom_fields.country.value != '' ){
FC.json.billing_address.country = FC.json.custom_fields.country.value;
}
}
});
From my basic testing, this seems to work on the surface. I guess the other check could be to run some validation to ensure provided ISO code was valid? (Though this seems to be covered in the form submission step as-is.) Is there anything I might be missing here?
Comments
  • fc_adamfc_adam FoxyCart Team
    @pixelchutes,

    That approach would be what I'd recommend. You would want to ensure that the template is updated accordingly though. You can do that by triggering the template re-render like this:

    FC.checkout.renderCustomerBilling() or FC.checkout.renderCustomerShipping()

  • pixelchutespixelchutes Member
    edited October 2015
    Thanks, Adam. Good point!

    I happen to have had a FC.checkout.render() already in place for some custom handling covering multiple portions of the layout, which would explain why it was working!

    Good to know it technically is supported, just not "out-of-the-box."
Sign In or Register to comment.