php array and returning a default value? -
here code:
<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 $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 $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>
which works great returns list of currencies , updates page accordingly, have on question if user has yet set value either select currency or apply first option hana_get_opt('_cc')
array default. here html generated code:
<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>
i no php coder , appreciate provided chris
based on assumption get_option('woocommerce_currency')
return null
if no currency selected
<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')); $currentcurrency = get_option('woocommerce_currency') if ($currentcurrency === false) { echo "select currency"; } else{ echo $currentcurrency; } ?> <span class="caret"></span> </a> <ul class="dropdown-menu currency_switcher"> <?php foreach ($currencies $currency) { if ($currency == $currentcurrency) 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>
replace if clause if ( $currentcurrency != null )
whatever applies, if get_option('woocommerce_currency')
returns other null
if not yet set