Skip to content

Instantly share code, notes, and snippets.

@galengidman
Last active July 17, 2017 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save galengidman/9ecdf3c8f9bb3c5dbba6 to your computer and use it in GitHub Desktop.
Save galengidman/9ecdf3c8f9bb3c5dbba6 to your computer and use it in GitHub Desktop.
Check if WooCommerce cart has items, add link to have if it does
<?php
function my_nav_wrap() {
// checks if there is an item in the cart
// returns default items + cart link if there is
// returns default items if the cart is empty
if (sizeof(WC()->cart->get_cart()) != 0) {
$wrap = '<ul id="%1$s" class="%2$s">';
$wrap .= '%3$s';
$wrap .= '<li class="cart">';
$wrap .= '<a href="' . WC()->cart->get_cart_url() . '" class="cart_totals">';
$wrap .= WC()->cart->get_cart_total();
$wrap .= '</a>';
$wrap .= '</li>';
$wrap .= '</ul>';
} else {
$wrap = '<ul id="%1$s" class="%2$s">%3$s</ul>';
}
return $wrap;
}
@Obvio
Copy link

Obvio commented Aug 7, 2015

line #13 should read:
$wrap .= '<a href="' . WC()->cart->get_cart_url() . '" class="cart_totals">';
you have an extra > before class="..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment