WC_Settings_Shipping::get_region_options()protectedWC 1.0

Get all available regions.

Метод класса: WC_Settings_Shipping{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_region_options( $allowed_countries, $shipping_continents );
$allowed_countries(int) (обязательный)
Zone ID.
$shipping_continents(int) (обязательный)
Zone ID.

Код WC_Settings_Shipping::get_region_options() WC 9.4.2

protected function get_region_options( $allowed_countries, $shipping_continents ) {
	$options = array();
	foreach ( $shipping_continents as $continent_code => $continent ) {
		$continent_data = array(
			'value'    => 'continent:' . esc_attr( $continent_code ),
			'label'    => esc_html( $continent['name'] ),
			'children' => array(),
		);

		$countries = array_intersect( array_keys( $allowed_countries ), $continent['countries'] );

		foreach ( $countries as $country_code ) {
			$country_data = array(
				'value'    => 'country:' . esc_attr( $country_code ),
				'label'    => esc_html( $allowed_countries[ $country_code ] ),
				'children' => array(),
			);

			$states = WC()->countries->get_states( $country_code );

			if ( $states ) {
				foreach ( $states as $state_code => $state_name ) {
					$country_data['children'][] = array(
						'value' => 'state:' . esc_attr( $country_code . ':' . $state_code ),
						'label' => esc_html( $state_name . ', ' . $allowed_countries[ $country_code ] ),
					);
				}
			}
			$continent_data['children'][] = $country_data;
		}
		$options[] = $continent_data;
	}

	return $options;
}