【发布时间】:2020-08-13 15:55:45
【问题描述】:
灵感来自:Get state name instead of the code in Woocommerce Display a preview of the custom field data in the Edit Billing and Shipping Address section on the my account page 在朋友@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
}
?>
` 我也要求它以同样的方式显示运输国家的名称。
非常感谢您能指导我。
【问题讨论】:
-
我相信这回答了你的问题Getting country name from country code in WooCommerce。所以你得到
echo WC()->countries->countries[ $custom_user_meta ]; -
您好@7uc1f3r 不是因为该帖子是指获取订单所在的国家/地区。我需要获取当前用户的帐单和送货国家/地区的名称。
-
好吧,你可以使用
WC()->countries->countries[ $custom_user_meta ];,而不是$order->get_shipping_country()。 -
@7uc1f3r 什么也没显示。您可以添加完整的代码。
标签: php wordpress woocommerce hook-woocommerce