@subwebsites
The province or state are not autofilled because the returned billing_state or shipping_state value from Google Places API are different from the default WooCommerce state codes.
For example, for this particular address: 4560, Jin Ke Lu
Places API: Shanghai Shi
WooCommerce State Value for the dropdown: CN10
————————————-
In order to make sure that the state field is autofilled with the Places API, we will match the result with the corresponding state code value in the autocomplete.js file.
var prop = this.component_form[f][1];
var billing_state_selected;
if(place.address_components[field].hasOwnProperty(prop)){
this.formFieldsValue[this.component_form[f][0]] = place.address_components[field][prop];
if ( this.component_form[f][0] == "billing_state" ) {
switch (place.address_components[field][prop]) {
case "Shanghai Shi":
billing_state_selected = "CN10";
break;
case "Yunnan Sheng":
billing_state_selected = "CN1";
break;
case "Beijing Shi":
billing_state_selected = "CN2";
break;
case "Tianjin Shi":
billing_state_selected = "CN3";
break;
// do the same for the remaining regions
}
// debugging
// console.log(this.component_form[f][0] + " = " + place.address_components[field][prop]);
}
This is what we will get when all the state codes are properly assigned:
-
This reply was modified 3 years, 3 months ago by cheey2003.
-
This reply was modified 3 years, 3 months ago by Yui.