Site logo

Archived topic

GP shopping cart icon into mobile menu

11 replies · Started by sparkle on December 13, 2022

Viewing posts 1–12 of 12

i moved my shopping cart menu from the primary navigation to the secondary navigation. now i'd also like to add it to my mobile menu (bonus points if it only appears when there's something in the cart). how can i adjust my code to do that?

from my functions:

 // gp move cart to secondary nav 
 add_filter( 'generate_woocommerce_menu_item_location', 'tu_move_menu_cart_item' );
 function tu_move_menu_cart_item() {
    return 'secondary';
 } 
 
// gp mobile nav  
 add_action( 'init', function() {
       register_nav_menu( 'mobile-menu', __( 'Mobile Menu' ) );
   } );
   
   add_filter( 'generate_mobile_header_theme_location', function() {
       return 'mobile-menu';
   } );

Hi Sparkle,

Can you try updating your code to something like this?:

 // gp move cart to secondary nav 
 add_filter( 'generate_woocommerce_menu_item_location', 'tu_move_menu_cart_item' );
 function tu_move_menu_cart_item() {
	if(wp_is_mobile()){
		return 'primary';
	}
    return 'secondary';
 } 
 
// gp mobile nav  
 add_action( 'init', function() {
       register_nav_menu( 'mobile-menu', __( 'Mobile Menu' ) );
   } );
   
   add_filter( 'generate_mobile_header_theme_location', function() {
       return 'mobile-menu';
   } );

Let us know how it goes.

sorry, just getting back to this. i replaced the old code with this and the cart stays in place in the desktop and tablet versions, but it does not appear in the mobile menu.

Can you show us the site?

yes :)

Hi there,

if you remove the PHP that you currently have that is moving the menu to the secondary nav.
And instead try adding this:


add_action('generate_after_secondary_menu', function(){
    echo generate_wc_do_cart_menu_item(); 
});

It will add a duplicate menu item to the secondary nav.
Then it will just require some CSS to hide the desktop primary nav cart, so that only displays on mobile.

ok! thanks! this did the trick. thanks. the css i added to mine if anyone finds this thread and wants it...

nav#sticky-navigation div.menu-bar-items {display: none;}

you guys are awesome. i recommend you every time someone asks me 'what theme should i use for...'

Glad to be of help! And thanks for sharing your CSS ...

no problem. nothing worse than reading a support thread and getting to an answer cliffhanger..... trust me, i know. :)

ps. please consider selling generatepress schwag. i'd proudly wear a tee. :)

haha yes, ill ask Tom, see if we can get my ugly mug printed on a Tee lol

oooh. GP Crew trading cards! hard to wear but i’d collect them all. lol

This archived topic is closed to new replies.