WC_Countries::get_continent_code_for_country()publicWC 2.6.0

Get continent code for a country code.

Method of the class: WC_Countries{}

No Hooks.

Return

String.

Usage

$WC_Countries = new WC_Countries();
$WC_Countries->get_continent_code_for_country( $cc );
$cc(string) (required)
Country code.

Changelog

Since 2.6.0 Introduced.

WC_Countries::get_continent_code_for_country() code WC 9.4.2

public function get_continent_code_for_country( $cc ) {
	$cc                 = trim( strtoupper( $cc ) );
	$continents         = $this->get_continents();
	$continents_and_ccs = wp_list_pluck( $continents, 'countries' );
	foreach ( $continents_and_ccs as $continent_code => $countries ) {
		if ( false !== array_search( $cc, $countries, true ) ) {
			return $continent_code;
		}
	}

	return '';
}