• Resolved Anonymous User 14477300

    (@anonymized-14477300)


    Can you export the country of the user using the WooCommerce Geolocation option, without the user having selected any Country or State option? Can you export the IP of the user?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    1. IP address
    open >Setup Fields>User and drag “Customer IP address” to export

    2. Country of user
    please, follow to https://algolplus.freshdesk.com/support/solutions/articles/25000016635-add-calculated-field-for-order-
    use meta key “geolocation_country” and following code.

    thanks, Alex

    add_filter('woe_get_order_value_geolocation_country',function ($value, $order,$fieldname) {
    	$user_ip_address = $order->get_customer_ip_address();
    	$geolocation_instance = new WC_Geolocation();
    	$user_geolocation = $geolocation_instance->geolocate_ip( $user_ip_address );
    	$value =  $user_geolocation['country'];
    	return $value;
    },10,3);
    Thread Starter Anonymous User 14477300

    (@anonymized-14477300)

    Amazing! Thank you very much! Is there a way to also export the STATE of the client, besides the Country?

    Thank you. Your plugin is superb

    Plugin Author algol.plus

    (@algolplus)

    you can try use

    $value = $user_geolocation['state'];

    • This reply was modified 6 years, 8 months ago by algol.plus.
    Plugin Author algol.plus

    (@algolplus)

    here is detailed reply 😉

    Please, follow to
    https://algolplus.freshdesk.com/support/solutions/articles/25000016635-add-calculated-field-for-order-

    use meta key “geolocation_state” and following code.

    add_filter('woe_get_order_value_geolocation_state',function ($value, $order,$fieldname) {
    	$user_ip_address = $order->get_customer_ip_address();
    	$geolocation_instance = new WC_Geolocation();
    	$user_geolocation = $geolocation_instance->geolocate_ip( $user_ip_address );
    	$value =  $user_geolocation['state'];
    	return $value;
    },10,3);
    Thread Starter Anonymous User 14477300

    (@anonymized-14477300)

    Thank you. The country export worked very well. But the state export didnt. State field is empty in preview mode. Maybe my woocommerce was not registering State and because of that the field is empty?

    I used “geolocation_state” as meta key. Column name “state”. Field format String. And in PHP custom field exactly the code you provided:

    add_filter(‘woe_get_order_value_geolocation_state’,function ($value, $order,$fieldname) {
    $user_ip_address = $order->get_customer_ip_address();
    $geolocation_instance = new WC_Geolocation();
    $user_geolocation = $geolocation_instance->geolocate_ip( $user_ip_address );
    $value = $user_geolocation[‘state’];
    return $value;
    },10,3);

    Plugin Author algol.plus

    (@algolplus)

    you’re right 🙁
    it’s impossible, I see this code inside geolocate_ip

    		return array(
    			'country' => $country_code,
    			'state'   => '',
    		);
    

    but you can call free services like https://ipapi.co/api/#complete-location
    just use wp_remote_get

    • This reply was modified 6 years, 8 months ago by algol.plus.
Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘GeoLocation of users’ is closed to new replies.