April 28, 2020
3rd Party Integration: Add Geolocation To Service Posts
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; }