靈感來自:獲取州名稱而不是 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 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消