Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\General\Schema

GeneralSettingsSchema::get_field_optionsprivateWC 1.0

Get options for specific field types.

Method of the class: GeneralSettingsSchema{}

No Hooks.

Returns

Array. Field options.

Usage

// private - for code of main (parent) class only
$result = $this->get_field_options( $field_id ): array;
$field_id(string) (required)
Field ID.

GeneralSettingsSchema::get_field_options() code WC 10.4.3

private function get_field_options( string $field_id ): array {
	switch ( $field_id ) {
		case 'woocommerce_currency':
			if ( ! function_exists( 'get_woocommerce_currencies' ) || ! function_exists( 'get_woocommerce_currency_symbol' ) ) {
				return array();
			}

			$currencies = get_woocommerce_currencies();
			$options    = array();

			foreach ( $currencies as $code => $name ) {
				$label            = wp_specialchars_decode( (string) $name );
				$symbol           = wp_specialchars_decode( (string) get_woocommerce_currency_symbol( $code ) );
				$options[ $code ] = $label . ' (' . $symbol . ') — ' . $code;
			}

			return $options;

		case 'woocommerce_default_country':
		case 'woocommerce_specific_allowed_countries':
		case 'woocommerce_specific_ship_to_countries':
			if ( ! function_exists( 'WC' ) ) {
				return array();
			}

			$countries = WC()->countries->get_countries();
			$states    = WC()->countries->get_states();
			$options   = array();

			foreach ( $countries as $country_code => $country_name ) {
				$country_states = $states[ $country_code ] ?? array();

				if ( empty( $country_states ) ) {
					$options[ $country_code ] = $country_name;
				} else {
					foreach ( $country_states as $state_code => $state_name ) {
						$options[ $country_code . ':' . $state_code ] = $country_name . ' — ' . $state_name;
					}
				}
			}

			return $options;
	}

	return array();
}