WC_Integration_MaxMind_Geolocation::get_geolocation()publicWC 1.0

Performs a geolocation lookup against the MaxMind database for the given IP address.

Метод класса: WC_Integration_MaxMind_Geolocation{}

Хуков нет.

Возвращает

Массив. Geolocation including country code, state, city and postcode based on an IP address.

Использование

$WC_Integration_MaxMind_Geolocation = new WC_Integration_MaxMind_Geolocation();
$WC_Integration_MaxMind_Geolocation->get_geolocation( $data, $ip_address );
$data(массив) (обязательный)
Geolocation data.
$ip_address(строка) (обязательный)
The IP address to geolocate.

Код WC_Integration_MaxMind_Geolocation::get_geolocation() WC 8.7.0

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' => '',
	);
}