这是我的代码:
<div class="search-menu">
<div class="btn-group fc">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<?php
$currencies = explode(',', hana_get_opt('_cc'));
foreach ($currencies as $currency) {
if ($currency == get_option('woocommerce_currency')){
echo $currency;
break;
}else{
echo "Select Currency";
break;
}
}
?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu currency_switcher">
<?php
foreach ($currencies as $currency) {
if ($currency == get_option('woocommerce_currency'))
echo '<li><a href="#" class="reset default" data-currencycode="' . $currency . '">' . $currency . '</a></li>';
else
echo '<li><a href="#" data-currencycode="' . $currency . '">' . $currency . '</a></li>';
}
?>
</ul>
</div>
</div>
效果很好,它会返回我的货币列表并相应地更新页面,我只是质疑用户是否尚未设置值我希望它说要么选择货币,要么只应用我hana_get_opt('_cc')
数组中的第一个选项作为默认。这是html生成的代码:
<div class="btn-group fc">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">undefined<span class="caret"></span></a>
<ul class="dropdown-menu currency_switcher">
<li><a href="#" class="reset default active" data-currencycode="SEK">SEK</a></li>
<li><a href="#" data-currencycode="EUR">EUR</a></li>
</ul>
</div>
我不是 php 编码器,非常感谢克里斯提供的任何帮助