Get the billing state code to display the name in WooCommerce

Viewed 7451

I am trying desperately to understand, how WooCommerce translates certain countries county/state names into database field constants and back.

ie.

I have a customer from Greece, who happens to be from a county/state, that I haven't got letters on this keyboard to name.

enter image description here

Apparently even WooCommerce doesn't have letters for it, for in the database, the county/state is also saved as just "D".

What function can I use to revert it to it's frontend form of

enter image description here


Edit 1.

I found something like this, but im unsure how to use it.

enter image description here

3 Answers

here is my Code

    $user = wp_get_current_user();
    $country_name_data = get_user_meta($user->ID, 'billing_country', true);
    $state_name_data = get_user_meta($user->ID,'billing_state',true);
    
    $countries_obj = new WC_Countries();
    $countries_array = $countries_obj->get_countries();
    $country_states_array = $countries_obj->get_states();

    $country_name = $countries_array[$country_name_data];
    $state_name = $country_states_array[$country_name_data][$state_name_data];

echo "Country Name : ". $country_name ."<br/>"."State Name ":$state_name;
Related