16 replies [Last post]
adigit's picture
Offline
Joined: 02/29/2008
Juice: 15
Was this information Helpful?

Hi All,

can you tell how to change the default country in checkout?

currently, when user clicked checkout, the default selected country is always "United States". I have already imported China and Singapore, how to make China as default?

Thanks a lot!

rapsli's picture
Offline
Joined: 03/06/2008
Juice: 21
Re: How to change default country in checkout?

would be interesting, cuz in the country section there's no way to set the default country, so I'm guessing this is not possible...?

adigit's picture
Offline
Joined: 02/29/2008
Juice: 15
Pity! I tried to remove all

Pity!

I tried to remove all countries except China, however, the "Zone select" got dark.

anyone can help? tks!

mavielma's picture
Offline
Joined: 01/23/2008
Juice: 182
Re: Pity!

Here is a bad way solution. The zone fields commented in file modules\ubercart\uc_cart\uc_cart_checkout_pane.inc. I have attached the sample.

AttachmentSize
uc_cart_checkout_pane.zip 4.93 KB
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: How to change default country in checkout?

The default country is the same as your store's address. Check both the Store settings and the Shipping quote settings.

adigit's picture
Offline
Joined: 02/29/2008
Juice: 15
Re: Re: How to change default country in checkout?

Thanks a lot, both kind men!

I changed the Store Settings and problem solved.

keithloh's picture
Offline
Joined: 02/28/2009
Juice: 10
Re: Re: Re: How to change default country in checkout?

Is there a way to properly set an order for countries? My client wants USA, Canada and UK to be at the top and all the other countries in alphabetical. With the method above, all we can do is set one country to be the default.

rosscoe's picture
Offline
Joined: 03/04/2012
Juice: 6
Re: Re: Re: Re: How to change default country in checkout?

Hi. This is how I altered the order of the countries in the shipping and billing panes while still preserving the zone info:

<?php
function hook_form_alter(&$form, &$form_state, $form_id) {
if (
$form_id == 'uc_cart_checkout_form') {
    unset(
$form['panes']['billing']['billing_country']['#options'][840]);
    unset(
$form['panes']['billing']['billing_country']['#options'][124]);
   
$form['panes']['billing']['billing_country']['#options'] = array(124 => 'Canada', 840 => 'United States') + $form['panes']['billing']['billing_country']['#options'];
}
}
?>

I hope this helps someone. Cheers!

redcam's picture
Offline
Joined: 02/06/2012
Juice: 11
which file?

Hello,

Which file did you add this code to?

rosscoe's picture
Offline
Joined: 03/04/2012
Juice: 6
Hi redcam, I added this code

Hi redcam,

I added this code to a custom module I created in sites/all/modules/. If you aren't familiar with creating modules you can check out a tutorial here: http://drupal.org/node/206753. Keep in mind that although I named my function hook_form_alter in the code above, you will need to rename it yourmodulename_form_alter. Look into the Drupal hook system documentation for more information about this.

Cheers

ngaur@drupal.org's picture
Offline
Joined: 04/03/2009
Juice: 8
GeoIP ?

Thanks for that.

It would be very cool though if the ubercart software could make an intelligent guess based on looking up the IP of the user through GeoIP where it's installed.

noah's picture
Offline
Joined: 07/27/2009
Juice: 16
override default country

This was undesirable in the case of my client's website. They are a North American company located in Canada who wanted USA to be the default option. After some frustration trying to override the defaults in a custom Drupal module, I eventually went and modified the core Ubercart code. I would love to see 'default country' as an option in store configuration.

In ubercart/uc_store/uc_store.module:

function uc_zone_select
changed:

$country_id = uc_store_default_country();

to:

$country_id = 840; //usa

function uc_country_select
changed:

$default = db_result(db_query("SELECT country_id FROM {uc_countries} WHERE country_id = %d AND version > 0", empty($default) ? 0 : intval($default)));

to:

  if (!isset($default))
  {
  $default = 840; //usa
  }
checkmark's picture
Offline
Joined: 11/23/2009
Juice: 21
I second this request

I'm in the same situation: Canadian store wanting US as the default country. Making code mods is beyond me, so I'm setting my store location as "US", which fixes this problem, but this shows up in the invoice. I second the request for a separate place to choose the country default, separate from the actual store location.

Thanks for making great software guys, I'm amazed this stuff works as well as it does!

redben's picture
Offline
Joined: 03/02/2009
Juice: 19
Please select

It would be much more flexible to have an - Please Select - without making any assumptions

freatida's picture
Offline
Joined: 10/20/2009
Juice: 108
Re: How to change default country in checkout?

I agree, a Please Select makes much more sense. In the same way there is one for the State/Province select box

Tanjerine's picture
Offline
Bug FinderInternationalizationizerNot KulvikThe other woman.
Joined: 08/31/2007
Juice: 235
Re: How to change default country in checkout?

+1 on this.

perceptum's picture
Offline
Joined: 05/01/2011
Juice: 6
GeoIP Module Integration

Hi,

I needed this for a project as well. I created a small module to achieve it. Its in early stages, so if you use it feel free to add requests for additions or changes to the issue queue. It will hopefully be updated to a full drupal.org project in the next few days.

http://drupal.org/sandbox/perceptum/1146104

Hope this begins to help

Bryan