• Resolved seevold

    (@seevold)


    Hello,

    I have implemented this snippet to get the address autocomplete to a spesific country. This code works only on an “address” field.

    When I use it on a “single line text” field with address autocomplete enabled it wont work. Do you have any suggestions for how I can edit the snippet to make it work on “single line text” field as well?

    /**
     * Restrict address autocomplete to a specific country
     *
     * @link https://wpforms.com/developers/how-to-restrict-address-autocomplete-to-a-specific-country/
     */
     
    function wpf_dev_geo_autocomplete_default_country( ) {
    ?>
    <script type="text/javascript">
        jQuery(function($){
             
            var formID = 2757; // Change form ID
             
            var addressFieldID = 21; // Change address field ID 
             
            // Find field place by country
            var stateField = window.WPFormsGeolocationGooglePlacesAPI.findFieldPlaceByPolitical($( #wpforms-${formID}-field_${addressFieldID}-state )[0]);
     
                // Put a country code here according to this list: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
     
            // Set default autocomplete country to Canada
            stateField.autocomplete.setComponentRestrictions({
                'country': [ 'ca' ],
            }); 
        });
    </script>
    <?php
    }
    add_action( 'wpforms_wp_footer_end', 'wpf_dev_geo_autocomplete_default_country', 30 );
Viewing 1 replies (of 1 total)
  • Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @seevold,

    Thanks for reaching out!

    Please note that the address autocomplete feature requires our Geolocation addon, which is only available with the Pro license level or higher.

    If you have an active license subscription with us, could you please submit a support ticket through the WPForms account dashboard when you have a chance? 

    From there, our support team will be able to take a closer look at your request.

    I apologize that we’re not able to respond to paid version questions here in the www.ads-software.com support forums for the free version, but I really appreciate your help!

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘Restrict Address Autocomplete to a Specific Country’ is closed to new replies.