Automattic\WooCommerce\Internal\Admin\Settings

SettingsUISchema::get_country_and_state_options │ private static │ WC 1.0

Build country and state options for a legacy country selector.

Method of the class: SettingsUISchema{}

No Hooks.

Returns

array.

Usage

$result = SettingsUISchema::get_country_and_state_options( $countries ): array;
$countries(WC_Countries) (required)
Countries controller.

SettingsUISchema::get_country_and_state_options() code WC 11.2.1

private static function get_country_and_state_options( \WC_Countries $countries ): array {
	$options = array();
	foreach ( $countries->get_countries() as $country_code => $country_label ) {
		$states = $countries->get_states( $country_code );
		if ( $states ) {
			foreach ( $states as $state_code => $state_label ) {
				$options[] = array(
					'label' => wp_strip_all_tags( $country_label . ' — ' . $state_label ),
					'value' => $country_code . ':' . $state_code,
				);
			}
			continue;
		}

		$options[] = array(
			'label' => wp_strip_all_tags( $country_label ),
			'value' => (string) $country_code,
		);
	}

	return $options;
}