我目前有两个通过后端创建的菜单。我需要根据地理位置激活菜单, 该菜单已设置了默认的货币设置。后端的菜单名称是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;
}
因此, 基本上我需要做的是在美国以外的任何地方将Main和Main International设置为Main菜单。我已经审查了食典, 但不太确定如何实施这种最简单的方法
#1
可以在模板文件(例如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
}
?>
#2
<?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
}
?>
评论前必须登录!
注册