仅显示当前用户的帐单和送货国家/地区名称,而不是国家/地区代码

灵感来自:获取州名称而不是 Woocommerce 中的代码 在我的帐户页面上的编辑帐单和送货地址部分显示自定义字段数据的预览在朋友 @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 

}

?>

` 我也要求以同样的方式显示发货国家/地区的名称。


我非常感谢您能指导我。


富国沪深
浏览 63回答 1
1回答

繁星coding

你可以使用WC()->countries->countries[ 'COUNTRY CODE' ];<?php$custom_user_meta = get_user_meta(get_current_user_id(), 'billing_country', true);if( ! empty($custom_user_meta) ) {?>&nbsp; &nbsp; <p>&nbsp; &nbsp; <?php&nbsp; &nbsp; // Get country name&nbsp; &nbsp; $country_name = WC()->countries->countries[ $custom_user_meta ];&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; printf( '<strong>Country / Region:</strong> ' . esc_html( '%s' ), esc_html($country_name) );&nbsp; &nbsp; ?>&nbsp;&nbsp; &nbsp; </p>&nbsp; &nbsp; <?php&nbsp;}?>
打开App,查看更多内容
随时随地看视频慕课网APP