WordPress at Your Fingertips
function is not described

WC_Geolocation::get_country_code_from_headers() private WC 3.9.0

Fetches the country code from the request headers, if one is available.

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

No Hooks.

Return

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.

Code of WC_Geolocation::get_country_code_from_headers() WC 5.9.0

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