- This topic has 11 replies, 4 voices, and was last updated 3 years, 2 months ago by
sparkle.
-
AuthorPosts
-
December 13, 2022 at 10:10 am #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'; } );December 13, 2022 at 5:36 pm #2461051Fernando 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.
February 17, 2023 at 10:47 am #2537173sparkle
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.
February 17, 2023 at 2:12 pm #2537348Ying
StaffCustomer SupportCan you show us the site?
February 17, 2023 at 2:13 pm #2537353sparkle
yes 🙂
February 19, 2023 at 5:07 am #2538624David
StaffCustomer SupportHi 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.February 19, 2023 at 7:01 am #2538702sparkle
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…’
February 19, 2023 at 7:27 am #2538715David
StaffCustomer SupportGlad to be of help! And thanks for sharing your CSS …
February 19, 2023 at 7:33 am #2538723sparkle
no problem. nothing worse than reading a support thread and getting to an answer cliffhanger….. trust me, i know. 🙂
February 19, 2023 at 7:34 am #2538724sparkle
ps. please consider selling generatepress schwag. i’d proudly wear a tee. 🙂
February 20, 2023 at 3:29 am #2539595David
StaffCustomer Supporthaha yes, ill ask Tom, see if we can get my ugly mug printed on a Tee lol
February 20, 2023 at 5:56 am #2539783sparkle
oooh. GP Crew trading cards! hard to wear but i’d collect them all. lol
-
AuthorPosts
- You must be logged in to reply to this topic.