WC_Integration_MaxMind_Geolocation::get_geolocation( array $data, string $ip_address )

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


Description Description


Parameters Parameters

$data

(Required) Geolocation data.

$ip_address

(Required) The IP address to geolocate.


Top ↑

Return Return

(array) Geolocation including country code, state, city and postcode based on an IP address.


Top ↑

Source Source

File: includes/integrations/maxmind-geolocation/class-wc-integration-maxmind-geolocation.php

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

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.