I know i can limit the available countries by managing the address field.
However, I am wanting to use a rule to set only one country to be available in the address form, depending upon a geo lookup.
I already have a country lookup that is happening - I use context and rules to set a context for that country. Now, I want to only display the one country and no other country options?
Even just setting a dynamic default country would help.... but my rule to set the default value of the form element (customer_profile_billing[commerce_customer_address][und][0][country]) to US is not working.
any ideas?
Comments
Comment #1
rszrama commentedTo accomplish this through Rules, you'd have to actually create the customer profile and save it to the order when the shopping cart order was created. This isn't impossible, but it's not a trivial Rules configuration either. The simplest thing to do would be to alter the checkout form so only the option you wanted was available (ensuring the form was rebuilt for the target country at the same time). However, if you want to pursue the Rules option, I'd check around on #drupal-commerce in IRC to see if someone is around to walk you through it.
Comment #3
rudy.barrett commentedI was able to do this by modifying the default customer profile fields provided by Commerce:
admin/commerce/customer-profiles/types/billing/fields/commerce_customer_address
/admin/commerce/customer-profiles/types/shipping/fields/commerce_customer_address
Hope this helps someone in the future, it took me a minute to find.
Comment #4
pog21 commentedI don't have any "customer profiles" section within Commerce. Is there another way to access these field options?Doh! Easily fixed: Enable
Customer UImodule.Comment #5
Jurgen8en commentedI found a solution to set the countries programmatically.
Comment #6
Jurgen8en commentedMuch easier with the latest Address Field 7.x-1.0
To set default country and available countries
Comment #7
ptmkenny commented@jurgen8en: With Addressfield 1.2, I am getting the following error:
"Fatal error: Class 'ShippingRules' not found in /srv/bindings/3e6587f55074463ea17292eda4e1ac67/code/sites/all/modules/mycustommodule"
Is there an alternate way to load the class?
Comment #8
rszrama commentedThat looks unrelated to Drupal Commerce or anything else that we maintain and rather an issue with your custom module. Please refer to general Drupal API documentation for autoloading classes or post your question on https://drupal.stackexchange.com.
Comment #9
schiavone commented#4 worked for me. Enabled commerce_customer_ui
Go to /admin/commerce/customer-profiles/types/billing/fields
Where you can select what countries to list and a default country
Comment #10
AmolB commentedComment #9 from schiavone worked for me.
Comment #11
webengr commented#3 worked, thank you Rudy for sharing!