WC_Geolite_Integration::get_country_iso()
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.
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 since | 3.9.0 |
WC_Geolite_Integration::get_country_iso() WC Geolite Integration::get country iso code WC 9.7.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 ) ); }