WC_Settings_Shipping::get_region_options
Get all available regions.
Method of the class: WC_Settings_Shipping{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->get_region_options( $allowed_countries, $shipping_continents );
- $allowed_countries(int) (required)
- Zone ID.
- $shipping_continents(int) (required)
- Zone ID.
WC_Settings_Shipping::get_region_options() WC Settings Shipping::get region options code WC 10.9.1
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;
}