Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greathmaster/a68d845a0cfef6fd13e81af45e695830 to your computer and use it in GitHub Desktop.
Save greathmaster/a68d845a0cfef6fd13e81af45e695830 to your computer and use it in GitHub Desktop.
Save IP address and country to user meta on checkout in PMPro. Requires the Geo IP Detect plugin to be installed and activated
/*
Save IP address and country to user meta on checkout in PMPro.
Requires the Geo IP Detect plugin (https://wordpress.org/plugins/geoip-detect/)
to be installed and activated
*/
function save_ip_and_country_after_checkout($user_id, $morder)
{
$country = '';
$ip = '';
if(function_exists('geoip_detect2_get_client_ip'))
$ip = geoip_detect2_get_client_ip();
if(function_exists('geoip_detect2_get_info_from_current_ip'))
$country = geoip_detect2_get_info_from_current_ip()->country->name;
update_user_meta($user_id, 'pmpro_cust_ip', $ip);
update_user_meta($user_id, 'pmpro_cust_country', $country);
}
add_action('pmpro_after_checkout', 'save_ip_and_country_after_checkout', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment