Trying to use <?php echo $current_user->billing_country; ?>
to display the WooCommerce user billing country. This for example echo’s as AU if the customer has an Australian billing address. However, I would like to pull the full name in place of the country code.
The same applies for the billing_state. Instead of getting South Australia I get SA. Have made work through functions.php, however only if I add each state and country. This is obviously a great undertaking to map the worlds states to the state codes.
I believe I have done this before in a very simple way, but for whatever reason cannot figure it out at this moment.
The country and state are being used within a disable input field as the value
<input type="text" class="form-control" value="<?php echo $current_user->billing_country; ?>" disabled="">
Image of what we currently get
Image of what we want to get
WooCommerce has WC_Countries
class for this you can use it like this:
echo WC()->countries->countries['AU']; //To get country name by code
echo WC()->countries->states['AU']['SA']; //to get State name by state code
OR (in your case)
echo WC()->countries->countries[$current_user->billing_country]; //To get country name by code
echo WC()->countries->states[$current_user->billing_country][$current_user->billing_state]; //to get State name by state code
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With