WordPress at Your Fingertips
function is not described

WC_Integration_MaxMind_Database_Service::get_iso_country_code_for_ip() public WC 1.0

Fetches the ISO country code associated with an IP address.

{} It's a method of the class: WC_Integration_MaxMind_Database_Service{}

No Hooks.

Return

String. The country code for the IP address, or empty if not found.

Usage

$WC_Integration_MaxMind_Database_Service = new WC_Integration_MaxMind_Database_Service();
$WC_Integration_MaxMind_Database_Service->get_iso_country_code_for_ip( $ip_address );
$ip_address(string) (required)
The IP address to find the country code for.

Code of WC_Integration_MaxMind_Database_Service::get_iso_country_code_for_ip() WC 5.9.0

public function get_iso_country_code_for_ip( $ip_address ) {
	$country_code = '';

	if ( ! class_exists( 'MaxMind\Db\Reader' ) ) {
		wc_get_logger()->notice( __( 'Missing MaxMind Reader library!', 'woocommerce' ), array( 'source' => 'maxmind-geolocation' ) );
		return $country_code;
	}

	$database_path = $this->get_database_path();
	if ( ! file_exists( $database_path ) ) {
		return $country_code;
	}

	try {
		$reader = new MaxMind\Db\Reader( $database_path );
		$data   = $reader->get( $ip_address );

		if ( isset( $data['country']['iso_code'] ) ) {
			$country_code = $data['country']['iso_code'];
		}

		$reader->close();
	} catch ( Exception $e ) {
		wc_get_logger()->notice( $e->getMessage(), array( 'source' => 'maxmind-geolocation' ) );
	}

	return $country_code;
}