Site logo

[Resolved] GP shopping cart icon into mobile menu

Home Forums Support [Resolved] GP shopping cart icon into mobile menu

Home Forums Support GP shopping cart icon into mobile menu

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2460754
    sparkle

    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';
       } );
    #2461051
    Fernando
    Customer Support

    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.

    #2537173
    sparkle

    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.

    #2537348
    Ying
    Staff
    Customer Support

    Can you show us the site?

    #2537353
    sparkle

    yes 🙂

    #2538624
    David
    Staff
    Customer Support

    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.

    #2538702
    sparkle

    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…’

    #2538715
    David
    Staff
    Customer Support

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

    #2538723
    sparkle

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

    #2538724
    sparkle

    ps. please consider selling generatepress schwag. i’d proudly wear a tee. 🙂

    #2539595
    David
    Staff
    Customer Support

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

    #2539783
    sparkle

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

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.