문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top