Question

Ok so I know that to get the current user's location in WooCommerce you use

$woocommerce->customer->get_country( );

Woocommerce then returns the user's country as a 2 character user code i.e (GB,US,MX) My question is, where is WooCommerce getting this value? even when I am logged out it seems to get the correct location. Is this some kind of Geo coding or it uses a cookie or database to return a user inputed value?

Was it helpful?

Solution

It is using MaxMind API, class WC_Geolocation located inside includes folder. The MaxMind GeoLite Database will be periodically downloaded to your wp-content directory if you check to use geolocation, there is option in settings.

You can find talk when they added it to WooCommerce here: https://github.com/woothemes/woocommerce/issues/6969

OTHER TIPS

Never used WooCommerce before but in the past I have used GeoIP to get a users country and other information based on IP address. It's not always accurate though (country is likely to be accurate but city isn't)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top