简体   繁体   English

基于用户的Drupal 7商业模块计费国家选择

[英]Drupal 7 commerce module billing country selection based on user

I have a problem with Drupal 7 commerce module. 我对Drupal 7商务模块有问题。

We have a country drop-down in home page and user can select any country to proceed with shopping. 我们在主页上有一个国家/地区下拉菜单,用户可以选择任何国家/地区进行购物。

Once in commerce billing section currently shows default country as CANADA. 进入商务后,结算部分目前显示默认国家/地区为加拿大。 What i want to do here is based the home page country selection i have to set the same value to country drop-down in the billing section. 我要在此处执行的操作基于主页国家/地区选择,我必须在“结算”部分中为“国家/地区”下拉菜单设置相同的值。 Please anyone know how i can implement this?. 请任何人知道我可以如何实现?

I am new to Drupal 我是Drupal的新手

Same type of question can find here https://drupal.stackexchange.com/questions/120858/prepopulating-county-state-field-ajax-driven-field 相同类型的问题可以在这里找到https://drupal.stackexchange.com/questions/120858/prepopulating-county-state-field-ajax-driven-field

Can't you get back this country selected on homepage? 您无法找回在首页上选择的这个国家吗? Maybe it appears on the url and you can use current_path to get it? 也许它出现在URL上,您可以使用current_path来获取它吗? How do you deal with it when selected on homepage? 在首页上选择后如何处理?

EDIT: If you can access it anywhere, then you can probably use a hook_widget_form_alter in a custom module like this: 编辑:如果您可以在任何地方访问它,则可能可以在这样的自定义模块中使用hook_widget_form_alter:

function YOUR_MODULE_field_widget_form_alter(&$element, &$form_state, $context) {
    $element['#address']['country'] = 'US';
}

Replace the 'YOUR_MODULE' by your module name. 用模块名称替换“ YOUR_MODULE”。 And change 'US' by the ISO of the user's country. 并通过用户所在国家/地区的ISO更改“美国”。 And you should also probably add a conditional statement on form_id to apply this change only on checkout form. 而且,您可能还应该在form_id上添加条件语句,以仅在结帐表单上应用此更改。 I hope it works! 我希望它能起作用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM