How can I set a default value for the country in an addressfield? I'm trying to set the default value for a country in an addressfield (caught in hook_form_alter) and ensure that the associated fields (administrative area, etc.) are refreshed properly. How can I do this?
Finally figured it out. The idea is to emulate the code in addressfield_field_widget_form(). Here's the recipe:

 /**
  * Implements hook_form_FORMID_alter() for `commerce_checkout_form_checkout`.
  */
 function mymodule_form_commerce_checkout_form_checkout_alter(&amp;$form, &amp;$form_state) {
    // Get the addressfield element we're modifying.
    // Adapted from addressfield.module/addressfield_field_widget_form()
    $element =&amp; $form['customer_profile_shipping']['commerce_customer_address'][LANGUAGE_NONE][0];
    $element_key = $element['element_key']['#value'];
    $field = $form_state['field']['commerce_customer_address'][LANGUAGE_NONE]['field'];
    $instance = $form_state['field']['commerce_customer_address'][LANGUAGE_NONE]['instance'];
    $delta = $element['#delta'];
    $settings = $instance['widget']['settings'];
    $langcode = $element['#language'];
    $items = array($delta =&gt; $element['#address']);

    // Get the default address used to build the widget form elements, looking
    // first in the form state, then in the stored value for the field, and then
    // in the default values of the instance.
    $address = array();

    if (!empty($form_state['addressfield'][$element_key])) {
      // Use the value from the form_state if available.
      $address = $form_state['addressfield'][$element_key];
    }
    elseif (!empty($items[$delta]['country'])) {
      // Else use the saved value for the field.
      $address = $items[$delta];
    }
    else {
      // Otherwise use the instance default.
      $address = (array) $instance['default_value'][0];
    }

    // Merge in default values to provide a value for every expected array key.
    $countries = _addressfield_country_options_list($field, $instance);
    $address += addressfield_default_values($countries);

    // Set our default country.
    // THAT'S THE PAYLOAD!
    if ($address['country'] != $my_default_country) {
      $address['country'] = $my_default_country;
      $address['administrative_area'] = '';
    }

    // Add the form elements for the standard widget, which includes a country
    // select list at the top that reloads the available address elements when the
    // country is changed.
    if ($instance['widget']['type'] == 'addressfield_standard') {
      // Generate the address form.
      $context = array(
        'mode' =&gt; 'form',
        'field' =&gt; $field,
        'instance' =&gt; $instance,
        'langcode' =&gt; $langcode,
        'delta' =&gt; $delta,
      );
      $element = array_merge($element, addressfield_generate($address, $settings['format_handlers'], $context));

      // Mark the form element as required if necessary.
      $element['#required'] = $delta == 0 &amp;&amp; $instance['required'];
    }
  }