Created
May 7, 2019 00:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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