灵感来自:获取州名称而不是 Woocommerce 中的代码 在我的帐户页面上的编辑帐单和送货地址部分显示自定义字段数据的预览在朋友 @LoicTheAztec 的回答中,我打算显示该名称我的帐户页面的“国家/地区”部分(编辑帐单和送货地址) 包含以下代码,但它只显示国家/地区代码而不是完整的国家/地区名称:`<?php$custom_user_meta = get_user_meta(get_current_user_id(), 'billing_country', true);if( ! empty($custom_user_meta) ) { ?><p> <?phpprintf( '<strong>Country / Region:</strong> ' . esc_html( '%s' ), esc_html($custom_user_meta) );?> </p> <?php }?>` 我也要求以同样的方式显示发货国家/地区的名称。我非常感谢您能指导我。
1 回答

繁星coding
TA贡献1797条经验 获得超4个赞
你可以使用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
}
?>
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报
0/150
提交
取消