Site logo

Archived topic

Woocommerce cart icon as part of Primary Navigation

5 replies · Started by Stephen on March 12, 2022

Viewing posts 1–6 of 6

http://www.stephenlavender.site

David kindly gave me a code snippet to make the search icon part of my headers primary navigation in desktop as normally when you enable navigation search in primary navigation layout the search icon appears on a new line below the primary navigation.

When I select display cart in menu in Woocommerce layout the woocommerce cart also appears on a new line below my primary navigation.

- Is it possible to have that same woocommerce shopping bag with the number of items in the cart added on to the end of my primary navigation after the search icon please?

Thanks
Stephen

Hi Stephen,

Try this PHP snippet:

add_filter( 'wp_nav_menu_items', 'wc_menu_item_cart', 10, 2 );

function  wc_menu_item_cart( $nav, $args ) {

	return sprintf(
			'%1$s
			<li class="wc-menu-item menu-item-align-right %3$s %4$s">
				%2$s
			</li>',
			$nav,
			generatepress_wc_cart_link(),
			is_cart() ? 'current-menu-item' : '',
			$has_items
		);
}

Hi, thats brilliant thank you Ying the cart is in the nav menu now.

- Is it possible to make it blue so it stands out please ?

Yes, try this CSS:

.main-navigation .main-nav ul li.wc-menu-item a {
    color: var(--accent);
}

Perfect, thank you very much for all your help its the best customer service with generatepress.

Its time for me to change my main site over to generatepress...

You are welcome :)

Glad you are happy with our product and support!

This archived topic is closed to new replies.