Adding WooCommerce Cart Items link to WordPress menus

Here’s a quick function to create a nav menu item that contains cart items and a cart link. Useful to blend in WooCommerce features with an existing menu and design.

function add_last_nav_item($items) {
global $woocommerce;
return $items .= '<li class="menu-item-cart-item">CART: <a class="cart-contents" href="'.$woocommerce->cart->get_cart_url().'" title="View your shopping cart">'.sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count).' - '. $woocommerce->cart->get_cart_total().'</a></li>';

Just edit the $items variable to suit.

About Us   David Gavin Home   Oldfields Log Store

Author: Kieran Barnes

Kieran is a PHP developer with 15 years commercial experience. Specialist in WordPress, CakePHP, CubeCart and all things PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *