On admin/commerce/customer-profiles/types/billing/fields/commerce_customer_address and admin/commerce/customer-profiles/types/shipping/fields/commerce_customer_address one is supposed to select the available countries in a little box. This is not ideal. So I would like to do this programmatically (possibly with drush), is there already a quick solution for this or do I have to delve into this myself?

this is the little box

2 Answers 2


Depends what you mean by 'quick', really. Yes, you can do it programatically. With PHP:

$instance_config = field_info_instance('commerce_customer_profile', 'commerce_customer_address', 'shipping');

$instance_config['widget']['settings']['available_countries'] = array(
  // etc...


Or with JS (I'll let you work that one out, selecting a bunch of <option> tags based on a bunch of values is very easy).

IMO the time-consuming part is building up the array of default countries in the first place; no matter what automated method you use to put the values in, someone needs to spend the time choosing and preparing them. You can't get away from that.

  • This is going in the right direction. Where can I put this PHP code?
    – the
    Commented Jan 17, 2014 at 16:24
  • Depends - where do you need to run it?
    – Clive
    Commented Jan 17, 2014 at 16:28
  • You can get the code of the array from the webform module (I know it's there because it gives you the option to populate a select box with countries)
    – Pere
    Commented Jan 18, 2014 at 10:41
  • I ran it through drush php-script, still needed to open the form and save it before it works, before doing that the list of countries was empty at checkout. The list was the list of EU countries, pretty straightforward stuff (:
    – the
    Commented Jan 18, 2014 at 12:17

When being confronted with large lists in a small field, I normally pull up the developer tools of the browser, find the appropriate select-element and manually assign a suitable attribute (e.g. height=800px). Like this it is much easier to choose ranges of entries without loosing oversight.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.