Reputation: 47
I currently have two menus created via the back end. I need to activate the menu based on the geo location, which I have aleady setup to set a default currency. The menu names in the backend are Main and Main International. Below is the code:
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;
}
So essentially what I need to do is set the Main menu for the US and Main International for anywhere outside the US. I have reviewed the Codex but not quite sure how to implement that the easiest way possible
Upvotes: 1
Views: 1225
Reputation: 4151
Could it be something as easy as this in the template file (like header.php
)?
<?php
$userInfo = geoip_detect2_get_info_from_current_ip();
if ( $userInfo->country->isoCode == 'US' ){
wp_nav_menu(array('menu' => 1)); //Change 1 to be the Main ID
} else {
wp_nav_menu(array('menu' => 2)); //Change 2 to be the Main International ID
}
?>
Upvotes: 0
Reputation: 47
<?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
}
?>
Upvotes: 1