Copy this code to your theme’s functions.php and each call your ‘3rd party integrations’ plugin will make after a visitor submission (For CRMs API, for example), it will include the Country, City & State of the visitor by his IP address.

 

add_filter('Forms3rdPartyIntegration_service_filter_post', 'add_ip_to_3rdparty_post', 10, 3);
function add_ip_to_3rdparty_post($post, $service, $form) {
	$ip = $_SERVER['REMOTE_ADDR'];
	$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
	if(isset($details->country)) { 
		$post['country'] = $details->country;
		$post['city'] = $details->city;
		$post['state'] = $details->region;  
	};
	
    return $post;
}

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?