WordPress at Your Fingertips
function is not described

WC_Geolite_Integration::get_country_iso() public WC 1.0

Deprecated from version 3.9.0. It is no longer supported and can 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.

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

No Hooks.

Return

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 3.9.0

Code of WC_Geolite_Integration::get_country_iso() WC 5.8.0

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 ) );
}