You are here

function ip2country_form_uc_cart_pane_quotes_alter in IP-based Determination of a Visitor's Country 6

Same name and namespace in other branches
  1. 8 ip2country.module \ip2country_form_uc_cart_pane_quotes_alter()
  2. 7 ip2country.module \ip2country_form_uc_cart_pane_quotes_alter()

Implements hook_form_[form_id]_alter().

Alters Ubercart's uc_cart_pane_quotes() form to use ip2country's country determination as the default billing and delivery country. If the user's country hasn't been determined, the store country will be used instead.

File

./ip2country.module, line 236
Determination of user's Country based on IP.

Code

function ip2country_form_uc_cart_pane_quotes_alter(&$form, &$form_state) {
  global $user;
  if (isset($user->country_iso_code_2)) {
    if (module_exists('uc_store')) {
      $country_id = db_result(db_query("SELECT country_id from {uc_countries} WHERE country_iso_code_2 = '%s'", $user->country_iso_code_2));
      if (!$country_id) {
        $country_id = uc_store_default_country();
      }
      $form['delivery_country']['#default_value'] = $country_id;
    }
  }
}