How to Autocomplete addresses for WooCommerce


Google Address Autocomplete For WooCommerce empowers the users to experience in autofill billing and / or shipping address fields. It is easy and fast, helping to get results for a specific country; therefore, it saves time for the checkout process.

Add Autocomplete Address Woocommerce

This code is placed in “Code Snippets” An error occurred

Follow the tutorial below

    if(function_exists('is_checkout') && is_checkout()){
        $api_key = acf_get_setting('google_api_key');
        $url = "$**My_key**&libraries=places";
        wp_enqueue_script( 'google-maps-js', $url );            




//Attach the autocomplete to the DOM element
var billing_autocomplete = new google.maps.places.Autocomplete($('#billing_address_1')[0], {
    bounds: auckland_bounds, //restrict the search area
    strictBounds: true,        

//Define what information we want back from the API

//Define a handler which fires when an address is chosen from the autocomplete
billing_autocomplete.addListener('place_changed', function() {

  var place = billing_autocomplete.getPlace();

  if (place.address_components) {


      var street_number = place.address_components[0].short_name;
      var street_name = place.address_components[1].short_name
      var suburb = place.address_components[2].short_name;
      var city = place.address_components[3].short_name;
      var postcode = place.address_components[6].short_name;

      $('#billing_address_1').val(street_number + ' ' + street_name);



jack lee 2 years 2020-09-26T19:10:23-05:00 0 Answers 25 views 0

Leave an answer