inspired by: Get state name instead of the code in Woocommerce Display a preview of the custom field data in the Edit Billing and Shipping Address section on the my account page And in the answers of the friend @LoicTheAztec I intend to show the name of the country in the section (Edit Billing and Shipping Address) of the page my account with the following code, but it only shows me the country code instead of the full country name:`
<?php
$custom_user_meta = get_user_meta(get_current_user_id(), 'billing_country', true);
if( ! empty($custom_user_meta) )
{ ?>
<p> <?php
printf( '<strong>Country / Region:</strong> ' . esc_html( '%s' ), esc_html($custom_user_meta) );?>
</p> <?php
}
?>
` I also require it in the same way to show the name of the shipping country.
I appreciate a lot in what you could guide me please.
You could use WC()->countries->countries[ 'COUNTRY CODE' ];
<?php
$custom_user_meta = get_user_meta(get_current_user_id(), 'billing_country', true);
if( ! empty($custom_user_meta) ) {
?>
<p>
<?php
// Get country name
$country_name = WC()->countries->countries[ $custom_user_meta ];
printf( '<strong>Country / Region:</strong> ' . esc_html( '%s' ), esc_html($country_name) );
?>
</p>
<?php
}
?>