WC_Geolocation::get_country_code_from_headers
Fetches the country code from the request headers, if one is available.
Method of the class: WC_Geolocation{}
No Hooks.
Returns
String. The country code pulled from the headers, or empty string if one was not found.
Usage
$result = WC_Geolocation::get_country_code_from_headers();
Changelog
| Since 3.9.0 | Introduced. |
WC_Geolocation::get_country_code_from_headers() WC Geolocation::get country code from headers code WC 10.8.1
private static function get_country_code_from_headers() {
$country_code = '';
$headers = array(
'MM_COUNTRY_CODE',
'GEOIP_COUNTRY_CODE',
'HTTP_CF_IPCOUNTRY',
'HTTP_X_COUNTRY_CODE',
);
foreach ( $headers as $header ) {
if ( empty( $_SERVER[ $header ] ) ) {
continue;
}
$country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) );
break;
}
return $country_code;
}