Last active
July 17, 2017 07:36
-
-
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
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 | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line #13 should read:
$wrap .= '<a href="' . WC()->cart->get_cart_url() . '" class="cart_totals">';
you have an extra
>
beforeclass="..