WC_Geolite_Integration::get_country_isopublicWC 1.0

Deprecated since 3.9.0. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

Get country 2-letters ISO by IP address. Returns empty string when not able to find any ISO code.

Method of the class: WC_Geolite_Integration{}

No Hooks.

Returns

String.

Usage

$WC_Geolite_Integration = new WC_Geolite_Integration();
$WC_Geolite_Integration->get_country_iso( $ip_address );
$ip_address(string) (required)
User IP address.

Changelog

Deprecated since 3.9.0

WC_Geolite_Integration::get_country_iso() code WC 10.8.1

public function get_country_iso( $ip_address ) {
	wc_deprecated_function( 'get_country_iso', '3.9.0' );

	$iso_code = '';

	try {
		$reader = new MaxMind\Db\Reader( $this->database ); // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound
		$data   = $reader->get( $ip_address );

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

		$reader->close();
	} catch ( Exception $e ) {
		$this->log( $e->getMessage(), 'warning' );
	}

	return sanitize_text_field( strtoupper( $iso_code ) );
}