This guide will show you how to populate a Hidden field with the name of the visitor’s country.

Step 1

Install and configure the WordPress plugin GeoIP Detection.

Step 2

Add a Hidden element to the form, then go to the settings for it then the Data tab and enable the option Dynamic default value then enter the Parameter name country.

Dynamic default value country

Step 3

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

1
2
3
4
5
6
7
8
add_filter('quform_element_value_country', function ($value) {
    if (function_exists('geoip_detect2_get_info_from_current_ip')) {
        $record = geoip_detect2_get_info_from_current_ip();
        $value = $record->country->name;
    }
 
    return $value;
});
add_filter('quform_element_value_country', function ($value) {
    if (function_exists('geoip_detect2_get_info_from_current_ip')) {
        $record = geoip_detect2_get_info_from_current_ip();
        $value = $record->country->name;
    }

    return $value;
});
1
2
3
4
5
6
7
8
9
10
function my_get_ip_country($value)
{
    if (function_exists('geoip_detect2_get_info_from_current_ip')) {
        $record = geoip_detect2_get_info_from_current_ip();
        $value = $record->country->name;
    }
 
    return $value;
}
add_filter('quform_element_value_country', 'my_get_ip_country');
function my_get_ip_country($value)
{
    if (function_exists('geoip_detect2_get_info_from_current_ip')) {
        $record = geoip_detect2_get_info_from_current_ip();
        $value = $record->country->name;
    }

    return $value;
}
add_filter('quform_element_value_country', 'my_get_ip_country');
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy