Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how to assign a default country for new accounts


b00

Recommended Posts

what i wanted to do was to set a default country for someone creating a new customer acount. only one line of code needs to be changed. in my code example below i set the united states as the default (any other country can be picked by a customer). you can assign any country as default by changing this line of code. i found the united states id, 223, by looking in the oscommerce.sql file in the install folder. you can find your country id there or by browsing the country database

 

the file i changed the code in is /public_html/catalog/includes/functions/html_output.php

 

the original line of code:

$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

 

the new line of code:

$countries_array = array(array('id' => '223', 'text' => 'United States'));

 

i hope this helps :>)

Link to comment
Share on other sites

  • 2 weeks later...
Great post! I remember struggling with this last year... it's a definite plus for many many new installers.

 

Along these same lines.. is there a way to have the drop down box of states for the default country come up when first creating account? On mine, it has you type it in, then comes back with drop down box after you go to submit the account info.

Link to comment
Share on other sites

I second that motion.

 

What would be really very neat - is for the Country to default to the browser's country.

 

So, as a slight elaboration on the code above, Ive made the following code show "United Kingdom" for those with English-UK browsers, and "Please Select" for people in other countries. It would be great for this to work for all countries.

 

In the file: functions/html_output.php

 

Change this:

$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

 

To this:

	  if ($_SERVER['HTTP_ACCEPT_LANGUAGE'] == 'en-gb') {
	$countries_array = array(array('id' => '222', 'text' => 'United Kingdom'));
} else {
	$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));		
}

 

The last two letters of the variable HTTP_ACCEPT_LANGUAGE' denotes the country (mine is en-gb). These two letters are also stored in the Country table (in OSC) that is used to populate the drop down. Id be impressed if someone is able to make this fully dynamic. B)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...