Use the next WooCommerce code:
1 | $pd = WC_Geolocation::geolocate_ip(); |
You can then do: print_r($pd) and see all info which are provided by WooCommerce GEO IP functionality
Or you can simply get country code by: (GEO IP should be enabled in WOOCS)
1 | $country_code=$this->storage->get_val('woocs_user_country'); |
For example:
1 2 3 4 5 6 7 8 | $pd = WC_Geolocation::geolocate_ip(); global $WOOCS; if (isset($pd['country']) AND ! empty($pd['country'])) { //do smth here if user is from Spain, for example change currency to EUR if ('ES' == $pd['country']) { $WOOCS->set_currency('EUR'); } } |
Use Alpha-2 code for countries: https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
Read also: https://currency-switcher.com/function/woocs-get_currency_by_country/
