如何解决显示开票和运送国家的名称,而不是仅显示当前用户的国家/地区代码
灵感来自: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
}
?>
` 我还要求以同样的方式显示发货国的名称。
非常感谢您能为我提供指导。
解决方法
您可以使用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
}
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。