使用WP_AJAX获取Wordpress Woocommerce购物车中的product_ids数量

How could I show the number of distinct products (not just the number of cart items) in mini cart?

A sample cart table:

product      price  quantity 

aaa         25       2

bbb         35       3

cccc        55       9

Here's what I have tried:

foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product_id = array();
  $product_id = $cart_item['product_id'];
  echo count($product_id, COUNT_RECURSIVE); 
  }

Add the following code to functions.php

add_action( 'woocommerce_widget_shopping_cart_before_buttons', 'get_mini_cart_unique_items' );
function get_mini_cart_unique_items() {
    echo  "<p>" . __( 'Unique Items', 'woocommerce' ) . ": " . count( WC()->cart->get_cart() ) . "</p>";    
}