靈感來(lái)自:獲取州名稱(chēng)而不是 Woocommerce 中的代碼 在我的帳戶(hù)頁(yè)面上的編輯帳單和送貨地址部分顯示自定義字段數(shù)據(jù)的預(yù)覽在朋友 @LoicTheAztec 的回答中,我打算顯示該名稱(chēng)我的帳戶(hù)頁(yè)面的“國(guó)家/地區(qū)”部分(編輯帳單和送貨地址) 包含以下代碼,但它只顯示國(guó)家/地區(qū)代碼而不是完整的國(guó)家/地區(qū)名稱(chēng):`<?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 }?>` 我也要求以同樣的方式顯示發(fā)貨國(guó)家/地區(qū)的名稱(chēng)。我非常感謝您能指導(dǎo)我。
1 回答

繁星coding
TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊
你可以使用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 關(guān)注
- 115 瀏覽
添加回答
舉報(bào)
0/150
提交
取消