You are here

function ip2country_form_uc_cart_checkout_form_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_checkout_form_alter()
  2. 7 ip2country.module \ip2country_form_uc_cart_checkout_form_alter()

Implements hook_form_[form_id]_alter().

Alters Ubercart's uc_cart_checkout_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 213
Determination of user's Country based on IP.

Code

function ip2country_form_uc_cart_checkout_form_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['panes']['billing']['billing_country']['#default_value'] = $form['panes']['delivery']['delivery_country']['#default_value'] = $country_id;
    }
  }
}