灵感来自: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并且在朋友@LoicTheAztec的回答中,我打算在(编辑帐单和送货地址)部分中显示国家名称 > 页面上的我的帐户,其中包含以下代码,但仅显示国家代码而不是完整的国家名称:
<?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
}
?>
` 我还要求以同样的方式显示发货国的名称。
非常感谢您能为我提供指导。
答案 0 :(得分:2)
您可以使用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
}
?>