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?
For example:
- 3 * product A
- 2 * product B
WC()->cart->get_cart_contents_count()
would return 5.
But we want to get 2.
You can simply use
count(WC()->cart->get_cart());
asget_cart()
returns an array of items.Documentation