我目前通过后端创建了两个菜单。我需要根据地理位置激活菜单,我已经设置了默认货币。后端的菜单名称是Main和Main International。以下是代码:
function geo_client_currency($client_currency){
$userInfo = geoip_detect2_get_info_from_current_ip();
if ($userInfo->country->isoCode == 'US'){
$client_currency = 'USD'; //currency code
}
else {
$client_currency = 'INR';
}
return $client_currency;
}
基本上我需要做的是为美国以外的任何地方设置美国和主要国际的主菜单。我已经审查了食典委,但不太确定如何以最简单的方式实施
答案 0 :(得分:0)
在模板文件中是否可以像这样简单(如header.php
)?
<?php
$userInfo = geoip_detect2_get_info_from_current_ip();
if ( $userInfo->country->isoCode == 'US' ){
wp_nav_menu(array('menu_id' => 1)); //Change 1 to be the Main ID
} else {
wp_nav_menu(array('menu_id' => 2)); //Change 2 to be the Main International ID
}
?>
答案 1 :(得分:0)
<?php
$userInfo = geoip_detect2_get_info_from_current_ip();
if ( $userInfo->country->isoCode == 'US' ){
wp_nav_menu( array( 'theme_location' => 'nav-menu', 'menu'=> 'Main' , 'depth' => 3, 'container' => false, 'menu_class' => 'sf-menu', 'walker' => new thb_MegaMenu ) );
} else {
wp_nav_menu( array( 'theme_location' => 'nav-menu', 'menu'=> 'Main International' , 'depth' => 3, 'container' => false, 'menu_class' => 'sf-menu', 'walker' => new thb_MegaMenu ) ); //Change 2 to be the Main International ID
}
&GT;