Skip to content

Instantly share code, notes, and snippets.

@craigcooperxyz
Last active October 7, 2015 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigcooperxyz/7b6a0510959178cd143a to your computer and use it in GitHub Desktop.
Save craigcooperxyz/7b6a0510959178cd143a to your computer and use it in GitHub Desktop.
Add WooCommerce cart link to primary menu when cart is not empty
<?php
/*
*
* Wordpress and WooCommerce
* Add a "Cart" link to the menu when the cart is not empty
*
* When a customer adds an item to their woocommerce cart, a cart
* link will be added to the primary menu.
*
*/
add_filter( 'wp_nav_menu_items', 'pilgrim_add_cart_link', 10, 2 );
function pilgrim_add_cart_link( $items, $args ) {
if ($args->theme_location == 'primary') {
if (sizeof(WC()->cart->get_cart()) != 0) {
$items .= '<li><a href="/cart/">My Cart</a></li>';
}
}
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment