WC_Integration_MaxMind_Geolocation::get_geolocation
Performs a geolocation lookup against the MaxMind database for the given IP address.
Method of the class: WC_Integration_MaxMind_Geolocation{}
No Hooks.
Returns
Array. Geolocation including country code, state, city and postcode based on an IP address.
Usage
$WC_Integration_MaxMind_Geolocation = new WC_Integration_MaxMind_Geolocation(); $WC_Integration_MaxMind_Geolocation->get_geolocation( $data, $ip_address );
- $data(array) (required)
- Geolocation data.
- $ip_address(string) (required)
- The IP address to geolocate.
WC_Integration_MaxMind_Geolocation::get_geolocation() WC Integration MaxMind Geolocation::get geolocation code WC 10.8.1
public function get_geolocation( $data, $ip_address ) {
// WooCommerce look for headers first, and at this moment could be just enough.
if ( ! empty( $data['country'] ) ) {
return $data;
}
if ( empty( $ip_address ) ) {
return $data;
}
$country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address );
return array(
'country' => $country_code,
'state' => '',
'city' => '',
'postcode' => '',
);
}