WooCommerce – get number of different products in cart

There is WC()->cart->get_cart_contents_count() to show the total number of products in the WooCommerce cart.

But how do you get the number of different products?

Read More

For example:

  • 3 * product A
  • 2 * product B

WC()->cart->get_cart_contents_count() would return 5.
But we want to get 2.

Related posts

2 comments

  1. $cart = $_SESSION['wfcart'];
    $count=0
    foreach($cart->items as $item){
        $count+= $cart->itemqtys[$item];
    }
    

Comments are closed.