Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Setting default country in countries drop down


Guest

Recommended Posts

This is something I had wrestled with for some time, until the obvious hit me..

 

I tried various ways to output a sorted countries list, changing the country I wanted at top to be ID 0 and whatnot, didnt work. Finally I relaized I was overlooking the obvious of using <option .... selected>

 

Thankfully, the requisite functions have built-in "selected" handling, thus setting your default country is easy.

 

Edit create_account.php and find

 

              <tr>
               <td class="main"><?php echo ENTRY_COUNTRY; ?></td>
               <td class="main"><?php echo tep_get_country_list('country') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>
             </tr>

 

you want to change this line

php echo tep_get_country_list('country') .

to be

php echo tep_get_country_list('country','223') .

223 == the country ID for United States. YOu can set that to be any country by looking either in the database countries list for your countries ID, or even easier, look at the HTML of the create_account.php page and find where the country drop down list is, search for your country and grab the "value".

 

Hope this helps.

Link to comment
Share on other sites

  • 2 weeks later...

In addition, you'll also have edit /includes/modules/address_book_details.php to change the following line:

 

<td class="main"><?php echo tep_get_country_list('country', $entry['entry_country_id']) . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

 

to:

 

<td class="main"><?php echo (($entry['entry_country_id'] == '') ? tep_get_country_list('country', 223) : tep_get_country_list('country', $entry['entry_country_id'])) . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

Link to comment
Share on other sites

Hi, to add the drop down list of your country states in create_account.php.

 

I changed this:

 

<?php
     if ($process == true) {
     $entry_state_has_zones = ($revisar['total'] > 0);
     if ($entry_state_has_zones == true) {
       $zones_array = array();
       $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' order by zone_name");
       while ($zones_values = tep_db_fetch_array($zones_query)) {
         $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);        }
       echo tep_draw_pull_down_menu('state', $zones_array);
     } else {
       echo tep_draw_input_field('state');
     }
   } else {
     echo tep_draw_input_field('state');
   }

   if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;
?>

 

To:

 

<?php
//    if ($process == true) {
$revisar_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = 138");
     $revisar = tep_db_fetch_array($revisar_query);
     $entry_state_has_zones = ($revisar['total'] > 0);
     if ($entry_state_has_zones == true) {
       $zones_array = array();
       $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 138 order by zone_name");
       while ($zones_values = tep_db_fetch_array($zones_query)) {
         $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);        }
       echo tep_draw_pull_down_menu('state', $zones_array);
     } else {
       echo tep_draw_input_field('state');
     }
//    } else {
//      echo tep_draw_input_field('state');
//    }

   if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;
?>

Link to comment
Share on other sites

To the modules/addres_book_details.php

 

I change this:

 

<?php
    if ($process == true) {
     $entry_state_has_zones = ($revisar['total'] > 0);
     if ($entry_state_has_zones == true) {
       $zones_array = array();
       $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' order by zone_name");
       while ($zones_values = tep_db_fetch_array($zones_query)) {
         $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
       }
       echo tep_draw_pull_down_menu('state', $zones_array);
     } else {
       echo tep_draw_input_field('state');
     }
   } else {
     echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
   }

   if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;
?></td>

 

To:

 

<?php
//   if ($process == true) {
$revisar_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = 138");
     $revisar = tep_db_fetch_array($revisar_query);
     $entry_state_has_zones = ($revisar['total'] > 0);
     if ($entry_state_has_zones == true) {
       $zones_array = array();
       $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 138 order by zone_name");
       while ($zones_values = tep_db_fetch_array($zones_query)) {
         $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
       }
       echo tep_draw_pull_down_menu('state', $zones_array, tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
     } else {
       echo tep_draw_input_field('state');
     }
//    } else {
//      echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
//    }

   if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;
?></td>

Link to comment
Share on other sites

You could just delete the other countries, but then if you ever change your mind you would have to load back in the countries you want to ship to.

 

I set a filter on my site. I just added another column to the Countries table called Show_Country (int) and then marked the ones that I wanted to include with a 1.

 

Then I just added that condition (WHERE Show_Country=1) to the SQL statement in the tep_get_countries function in includes/functions/general.php

I'd rather be flying!

Link to comment
Share on other sites

  • 5 months later...

In the pull-down list of US states, where can I edit this list? I can not find them.

L8r,

PopTheTop

 

Published osC Contributions:

- eCheck Payment Module v3.1

- Reviews in Product Display v2.0

- Fancier Invoice & Packingslip v6.1

- Admin Notes / Customer Notes v2.2

- Customer Zip & State Validation v2.2

- Search Box with Dropdown Category Menu v1.0

 

Pop your camper's top today!

It's a popup thing...

You wouldn't understand

Link to comment
Share on other sites

  • 3 months later...
To the modules/addres_book_details.php

 

I change this:

 

<?php
? ? if ($process == true) {
? ? ?$entry_state_has_zones = ($revisar['total'] > 0);
? ? ?if ($entry_state_has_zones == true) {
? ? ? ?$zones_array = array();
? ? ? ?$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' order by zone_name");
? ? ? ?while ($zones_values = tep_db_fetch_array($zones_query)) {
? ? ? ? ?$zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
? ? ? ?}
? ? ? ?echo tep_draw_pull_down_menu('state', $zones_array);
? ? ?} else {
? ? ? ?echo tep_draw_input_field('state');
? ? ?}
? ?} else {
? ? ?echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
? ?}

? ?if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;
?></td>

 

To:

 

<?php
// ? if ($process == true) {
$revisar_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = 138");
? ? ?$revisar = tep_db_fetch_array($revisar_query);
? ? ?$entry_state_has_zones = ($revisar['total'] > 0);
? ? ?if ($entry_state_has_zones == true) {
? ? ? ?$zones_array = array();
? ? ? ?$zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 138 order by zone_name");
? ? ? ?while ($zones_values = tep_db_fetch_array($zones_query)) {
? ? ? ? ?$zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
? ? ? ?}
? ? ? ?echo tep_draw_pull_down_menu('state', $zones_array, tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
? ? ?} else {
? ? ? ?echo tep_draw_input_field('state');
? ? ?}
// ? ?} else {
// ? ? ?echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
// ? ?}

? ?if (tep_not_null(ENTRY_STATE_TEXT)) echo ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;
?></td>

 

why do you edit the address_book_details.php ? Is this necessary? i made my state drop down box using something different but it never mentioned having to edit the address book. is this ok?

 

Jeremy

Link to comment
Share on other sites

  • 2 weeks later...

Most excellent thread!

 

The only thing that got me was not changing the country code for the state dropdown to 223 (US) from 138 (Mexico) after a straight cut and paste of the code.

 

OSC Lesson #654: Pay attention to what you are pasting, even if it seems simple.

Link to comment
Share on other sites

  • 3 months later...

Bluepony -

Could you post how you did that? That sounds like a really cool idea and I would love to give it a try.

Link to comment
Share on other sites

  • 2 months later...

Anyway to delete the Country drop down box alltogether and hardcode just one Country into the create_account file?

 

I'm an ex Cube cart user and I did it there .. but I'm still a newbie to OC .. not sure if its possible.

 

:rolleyes:

Link to comment
Share on other sites

  • 3 weeks later...
You could just delete the other countries, but then if you ever change your mind you would have to load back in the countries you want to ship to. 

 

I set a filter on my site. I just added another column to the Countries table called Show_Country (int) and then marked the ones that I wanted to include with a 1.

 

Then I just added that condition (WHERE Show_Country=1) to the SQL statement in the tep_get_countries function in includes/functions/general.php

 

That sounds pretty cool but can you give a bit more detail. Some of us aren't quite up to your speed. :blink:

Link to comment
Share on other sites

  • 2 months later...
You could just delete the other countries, but then if you ever change your mind you would have to load back in the countries you want to ship to.

 

I set a filter on my site. I just added another column to the Countries table called Show_Country (int) and then marked the ones that I wanted to include with a 1.

 

Then I just added that condition (WHERE Show_Country=1) to the SQL statement in the tep_get_countries function in includes/functions/general.php

 

Hi bluepony,

I added the table column, but am not sure where to add the sql statement (i.e. which line(s)). I tried several things and none worked, so if you could specify where the WHERE goes, it would be greatly appreciated.

 

Thanks!

Link to comment
Share on other sites

  • 1 month later...
edit create_account... edit address_book....

<_< NO NEED! :thumbsup:

 

Just edit includes\functions\html_output.php and amend the following bit to default ALL country LOVs to your shops country.

 

HTH

 

Si.

 

 

////
// Creates a pull-down list of countries
 function tep_get_country_list($name, $selected = '', $parameters = '') {

//**si**
if ( strlen($selected)==0 ) $selected = STORE_COUNTRY;
//**si**

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

for ($i=0, $n=sizeof($countries); $i<$n; $i++) {
  $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);
}

return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
 }

Link to comment
Share on other sites

  • 1 year later...

This was an easy change, both for the country and state dropdown edits.

 

I think one more edit would make it perfect.

 

With the new state drop down mod, how can it be made to default to "Please Select" in lieu of Alabama?

 

I noticed that "Please select" is not in the list at all.

 

How can I add "Please select" to the state dropdown and make that the default selection?

 

Thanks,

Brian

Link to comment
Share on other sites

  • 1 month later...

Hello, How would one go about deleting the drop down box for the country. I know how to delete it and hard code just text that says United States but that wouldn't input the country else where. So how can I remove the drop down list and just use have it list one default country?

 

-Thanks

Search the forum and contributions before posting. If that doesn't work, keep looking, then post. The forum is for seeking help and advice NOT for someone to do your work for you. Try to do something on your on, if you are going to run a shop then learn how it works.

Link to comment
Share on other sites

  • 2 weeks later...

What I would like to do is just remove the drop down box for the country cause I am only going to ship and sale to the United States. I would like for it to just say United States as the default country without the drop down box. I know how to remove the box and I could hard code the text United States into the form but it wouldn't carry over United States through out the site so it will post to invoices, address ect. If anyone knows how this can be achieved that would be great.

 

-Thanks

Search the forum and contributions before posting. If that doesn't work, keep looking, then post. The forum is for seeking help and advice NOT for someone to do your work for you. Try to do something on your on, if you are going to run a shop then learn how it works.

Link to comment
Share on other sites

  • 1 year later...
In addition, you'll also have edit /includes/modules/address_book_details.php to change the following line:

 

<td class="main"><?php echo tep_get_country_list('country', $entry['entry_country_id']) . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

 

to:

 

<td class="main"><?php echo (($entry['entry_country_id'] == '') ? tep_get_country_list('country', 223) : tep_get_country_list('country', $entry['entry_country_id'])) . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

 

so, this will make the address book to display selected country.. right?

"I am not a Newbie but I am not an Expert either..."
"Lets learn about osCommerce together!..."
Link to comment
Share on other sites

  • 3 weeks later...

Defaulting the country (site-wide) on a per-language basis:

 

  1. Check countries table in db to find the id for your country (or just view the source of the dropdown). In my below example, I'm using 13 for Australia.
  2. Edit includes/languages/english.php, add the following anywhere you like:
    define('DEFAULT_COUNTRY_ID', 13); // 13 = Australia
    If you were using multiple languages, you'd set the country for each one.
  3. includes/functions/html_output.php:
    function tep_get_country_list($name, $selected = DEFAULT_COUNTRY_ID, $parameters = '') {

 

Done. Using $selected = DEFAULT_COUNTRY_ID in the function arguments is a PHP language feature which defaults the variable to DEFAULT_COUNTRY_ID if none is already set.

 

Concise and simple. Enjoy.

Link to comment
Share on other sites

  • 1 year later...
Hello, How would one go about deleting the drop down box for the country. I know how to delete it and hard code just text that says United States but that wouldn't input the country else where. So how can I remove the drop down list and just use have it list one default country?

 

-Thanks

 

I will really appreciate if you can give me step by step instructions of how to delete the drop down box for the country and hard code text. If possible let me know how to delete the text boxes for city and state also and hard code it to display a specific country/city/state.

 

Thanx in advance

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...