为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
富国沪深 2023-10-01 17:03:55
灵感来自:获取州名称而不是 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 

}

?>


查看完整回答
反对 回复 2023-10-01
  • 1 回答
  • 0 关注
  • 57 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信