Skip to content

Instantly share code, notes, and snippets.

@salehahmadbabu
Created July 31, 2018 09:46
Show Gist options
  • Save salehahmadbabu/1ac208a02c3ce44b74c4abf968859e41 to your computer and use it in GitHub Desktop.
Save salehahmadbabu/1ac208a02c3ce44b74c4abf968859e41 to your computer and use it in GitHub Desktop.
<script>
// auto fill form values
jQuery('.pef-title').val(jQuery('.product-title-content').text());
jQuery('.pef-url').val(window.location.href);
// auto fill form values
jQuery('#productname').val("<?php the_title(); ?>");
jQuery('#pageurl').val(window.location.href);
// jQuery('#userip').val("<?php// echo $_SERVER['REMOTE_ADDR']; ?>");
//var IpAddress = $_SERVER['REMOTE_ADDR'];
<?php // ip = 8.8.8.8
function ip_details($IPaddress)
{
$json = file_get_contents("http://ipinfo.io/{$IPaddress}");
$details = json_decode($json);
return $details;
}
$ip = $_SERVER['REMOTE_ADDR'];
$details = ip_details("$ip");
$country_names = json_decode(file_get_contents("http://country.io/names.json"), true);
$country = $country_names[$details->country];
?>
var country = "<?php echo $country; ?>";
console.log(country);
jQuery('input[name=CountryName]').val(country);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment