Archived topic
Cart Icon / Search Icon Secondary Menu
9 replies · Started by tolis on March 26, 2022
hello, i have put cart icon and search icon to the secondary menu which is above primary menu but on mobile i have hide the secondary menu..how i can display the cart icon and search icon to mobile in primary menu without losing on desktop the icons in secondary menu..
Thanks in regards.
Hi Tolis,
Can you try activate the navigation search at customizer > layout > primary navigation, and activate the cart at customizer > layout > Woocommerce?
Once it's done, do the cart and search icon appear in the primary navigation?
If so, please link us to your site, we can add some custom CSS to hide them on desktop.
If not, can you share the code of adding cart and search to secondary navigation here?
i have shared you the link. on desktop i am ok, just want to show the cart and search in mobile menu right to the logo ( not in off canvas menu)
Thanks
Can you try the solution I mentioned in my last reply?
yeah i have them activated
So it doesn't work.
Can you share the code you are using which adds the icons to secondary navigation?
the code is
add_filter( 'generate_woocommerce_menu_item_location', 'tu_move_menu_cart_item' );
function tu_move_menu_cart_item() {
return 'secondary';
}
and
add_action( 'wp', function() {
if ( 'enable' === generate_get_option( 'nav_search' ) ) {
remove_action( 'generate_menu_bar_items', 'generate_do_navigation_search_button' );
add_action( 'generate_secondary_menu_bar_items', 'generate_do_navigation_search_button' );
remove_action( 'generate_inside_navigation', 'generate_navigation_search' );
add_action( 'generate_inside_secondary_navigation', 'generate_navigation_search' );
}
}, 20 );
Try change your codes to this:
add_filter( 'generate_woocommerce_menu_item_location', 'tu_move_menu_cart_item' );
function tu_move_menu_cart_item() {
if (!wp_is_mobile()) {
return 'secondary';
}
return 'primary';
}
add_action( 'wp', function() {
if ( 'enable' === generate_get_option( 'nav_search' ) && !wp_is_mobile() ) {
remove_action( 'generate_menu_bar_items', 'generate_do_navigation_search_button' );
add_action( 'generate_secondary_menu_bar_items', 'generate_do_navigation_search_button');
remove_action( 'generate_inside_navigation', 'generate_navigation_search' );
add_action( 'generate_inside_secondary_navigation', 'generate_navigation_search' );
}
}, 20 );
yeah it worked thank you very much ;)
You are welcome :)