Last active
October 7, 2015 21:40
-
-
Save craigcooperxyz/7b6a0510959178cd143a to your computer and use it in GitHub Desktop.
Add WooCommerce cart link to primary menu when cart is not empty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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