gpt4 book ai didi

php - 在 WooCommerce 中显示完整的国家名称而不是国家代码?

转载 作者:可可西里 更新时间:2023-11-01 00:08:11 25 4
gpt4 key购买 nike

尝试使用 <?php echo $current_user->billing_country; ?>显示 WooCommerce 用户账单国家。例如,如果客户的账单地址为澳大利亚,则回显为 AU。但是,我想用全名代替国家代码。

这同样适用于 billing_state。我没有得到南澳大利亚,而是得到了 SA。已通过 functions.php 完成工作,但前提是我添加每个州和国家/地区。这显然是一项将世界各州映射到各州代码的伟大事业。

我相信我以前以一种非常简单的方式做到了这一点,但无论出于何种原因目前无法弄清楚。

在禁用输入字段中使用国家和州作为值

<input type="text" class="form-control" value="<?php echo $current_user->billing_country; ?>" disabled="">

我们目前得到的图片

Image of what we currently get

我们想要得到的图像 Image of what we want to get

最佳答案

WooCommerce 有 WC_Countries 类,您可以像这样使用它:

echo WC()->countries->countries['AU']; //To get country name by code
echo WC()->countries->states['AU']['SA']; //to get State name by state code

或者(在你的情况下)

echo WC()->countries->countries[$current_user->billing_country]; //To get country name by code
echo WC()->countries->states[$current_user->billing_country][$current_user->billing_state]; //to get State name by state code

希望这对您有所帮助!

关于php - 在 WooCommerce 中显示完整的国家名称而不是国家代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45634195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com