Automattic\WooCommerce\Blocks\Utils
CartCheckoutUtils::get_country_data()
Gets country codes, names, states, and locale information.
Метод класса: CartCheckoutUtils{}
Хуков нет.
Возвращает
Массив
.
Использование
$result = CartCheckoutUtils::get_country_data();
Код CartCheckoutUtils::get_country_data() CartCheckoutUtils::get country data WC 9.8.5
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 = []; foreach ( array_keys( $all_countries ) as $country_code ) { $country_data[ $country_code ] = [ 'allowBilling' => isset( $billing_countries[ $country_code ] ), 'allowShipping' => isset( $shipping_countries[ $country_code ] ), 'states' => $country_states[ $country_code ] ?? [], 'locale' => $country_locales[ $country_code ] ?? [], ]; } return $country_data; }