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
you can try use
$value = $user_geolocation['state'];
-
This reply was modified 6 years, 8 months ago by
algol.plus.
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);
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.