Understanding WooCommerce Build-In Geolocation/ Geo_IP classes
I would like to show/hide a fee in the WooCommerce checkout process depending on the location of the user.
For this i would like to first use the IP address of the user to determine the location and later the address he enters.
I came across the build-in Geolocation ability of WooCommerce with the following classes:
- WC_Geo_IP (https://docs.woocommerce.com/wc-apidocs/class-WC_Geo_IP.html)
- WC_Geo_IP_Record (https://docs.woocommerce.com/wc-apidocs/class-WC_Geo_IP_Record.html)
- WC_Geolocation (https://docs.woocommerce.com/wc-apidocs/class-WC_Geolocation.html)
I’m able to get the users IP address with:
$geolocation = new WC_Geolocation(); $ipaddress = $geolocation->get_ip_address();
But i don’t seem to be able to get the users country code. How would i go about this?