I'm working on a Woocommerce theme and I need to grab just the number of items in my cart without any totals or other markup. I've tried using
<?php echo WC()->cart->get_cart_contents_count(); ?>
But it returns two spans span.amount and span.count and inside span.count it has the string "items" as well
Is there a way to return just the number of items in my cart, preferably as an int?
UPDATE:
So when using the following code:
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>">
<?php echo WC()->cart->get_cart_contents_count(); ?>
</a>
The extra markup above was returned but, by commenting out the anchor tags like so:
<!-- <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"> -->
<?php echo WC()->cart->get_cart_contents_count(); ?>
<!-- </a> -->
Only an int was returned.
Why is that?