• Hi @natekinkead,

    Great plugin btw. When I typed the address, it automatically fill the postal code, but the city and province are left blank. I was using WooCommerce Checkout Manager, with the city and province limited by “select options” element. But I’ve deactivated those, and also WooCommerce Checkout Manager, so the city and province fields now are “text input”. Still not working.

    Can you tell me what’s the probable cause of this, as I read other threads saying the city and province are auto populated for them?

    Thanks,
    Dicko

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Dicko Mas Soebekti

    (@dickoms)

    Hi,

    Additional info, I tried to look at the console log, so I enable this line from autocomplete.js

    Line 115: console.log(this.component_form[f][0] + " = " + place.address_components[field][prop]);

    And turned out there are 2 inputs for billing_state when I enter a new address:

    billing_state = foobar_city
    billing_state = foobar_province

    The values for foobar_city and foobar_province are correct, just that they’re both assigned to billing_state field. Is this the cause?

    Thanks,
    Dicko

    Plugin Contributor natekinkead

    (@natekinkead)

    What’s the link to your website?

    Thread Starter Dicko Mas Soebekti

    (@dickoms)

    Hi @natekinkead,

    I got it to work, needed to modify autocomplete.js a bit, the country is Indonesia (ID) btw.

    formFields : {
        'billing_address_1': '',
        'billing_address_2': '',
        'billing_kelurahan': '',
        'billing_kecamatan': '',
        'billing_city': '',
        'billing_state': '',
        'billing_postcode': '',
        'billing_country' : ''
    },
    formFieldsValue : {
        'billing_address_1': '',
        'billing_address_2': '',
        'billing_kelurahan': '',
        'billing_kecamatan': '',
        'billing_city': '',
        'billing_state': '',
        'billing_postcode': '',
        'billing_country' : ''
    },

    And another one.

    this.component_form =
    {
        'street_number': ['billing_address_1', 'short_name'],
        'route': ['billing_address_1', 'long_name'],
        'administrative_area_level_4': ['billing_kelurahan', 'short_name'],
        'administrative_area_level_3': ['billing_kecamatan', 'short_name'],
        'administrative_area_level_2': ['billing_city', 'long_name'],
        'administrative_area_level_1': ['billing_state', 'short_name'],
        'country': ['billing_country', 'long_name'],
        'postal_code': ['billing_postcode', 'short_name']
    };

    Please disregard the “kelurahan” and “kecamatan” fields, as they’re my custom fields.

    Also, since the “billing_state” field is a dropdown, and I only use 3 of the states, I added this code.

    var prop = this.component_form[f][1];
    if(place.address_components[field].hasOwnProperty(prop)){
        if (b_city_valid) {
    				if (place.address_components[field][prop] == "Daerah Khusus Ibukota Jakarta") place.address_components[field][prop] = "JK";
    				if (place.address_components[field][prop] == "Jawa Barat") place.address_components[field][prop] = "JB";
    				if (place.address_components[field][prop] == "Banten") place.address_components[field][prop] = "BT";
        		this.formFieldsValue[this.component_form[f][0]] = place.address_components[field][prop];
         		// console.log(this.component_form[f][0] + " = " + place.address_components[field][prop]);
       	}
    }

    This has to be done for both billing and shipping. But it’s working now.

    Thanks,
    Dicko

    Plugin Contributor natekinkead

    (@natekinkead)

    Glad you got it working for your custom fields. Thanks for sharing your solution.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘City & Province not auto populated’ is closed to new replies.