Automattic\WooCommerce\Blocks\Utils
CartCheckoutUtils::get_country_data
Gets country codes, names, states, and locale information.
Method of the class: CartCheckoutUtils{}
No Hooks.
Returns
Array.
Usage
$result = CartCheckoutUtils::get_country_data();
CartCheckoutUtils::get_country_data() CartCheckoutUtils::get country data code WC 10.7.0
public static function get_country_data() {
$billing_countries = WC()->countries->get_allowed_countries();
$shipping_countries = WC()->countries->get_shipping_countries();
$country_states = wc()->countries->get_states();
$all_countries = self::deep_sort_with_accents( array_unique( array_merge( $billing_countries, $shipping_countries ) ) );
$country_locales = array_map(
function ( $locale ) {
foreach ( $locale as $field => $field_data ) {
if ( isset( $field_data['priority'] ) ) {
$locale[ $field ]['index'] = $field_data['priority'];
unset( $locale[ $field ]['priority'] );
}
if ( isset( $field_data['class'] ) ) {
unset( $locale[ $field ]['class'] );
}
}
return $locale;
},
WC()->countries->get_country_locale()
);
$country_data = array();
foreach ( array_keys( $all_countries ) as $country_code ) {
$country_data[ $country_code ] = array(
'allowBilling' => isset( $billing_countries[ $country_code ] ),
'allowShipping' => isset( $shipping_countries[ $country_code ] ),
'states' => $country_states[ $country_code ] ?? array(),
'locale' => $country_locales[ $country_code ] ?? array(),
);
}
return $country_data;
}