Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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