I want to show cart items number if any or nothing, simple CART text

Question

I am making a custom WooCommerce site and stuck at coding the CART link.

I want the link to look simple text "CART" when there is no item in it. But to show the number of items if any like "CART (1)"— is it possible ?

I am currently using this code which I feel shows "0" of no item.

<a href="<?php echo esc_url(get_page_link(12)); ?>">Cart (<?php echo WC()->cart->get_cart_contents_count(); ?>)</a>

Can someone please help me out with this??? I want a conditional php code to show Cart items number only if there are any, otherwise show nothing.

0
Rishabh Jha 2 months 0 Answers 10 views 0

Leave an answer