Creating WP Shortcode for amount of items in Woocommerce cart

606 views Asked by At

I am trying to create a shortcode - [Count] - for a Woocommerce shop that allows me to include the amount of items in the cart inline with standard text.

I have tried (in my functions.php file):

function itemCount() {
  global $woocommerce;

  $items = sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);

  return $items;
}

add_shortcode('Count', 'itemCount');

I've researched this a fair bit and I can't seem to work it out so any assistance is greatly appreciated.

0

There are 0 answers