echo product id and product_item_key in cart [closed]

Techno Deviser, probably by mistake, in the foreach loop set value to $fragments['div.header-cart-count'] instead append it.

Try this modification:

function iconic_cart_count_fragments( $fragments ) {

     foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { 
        $fragments['div.header-cart-count'] .= '<div class="header-cart-count">' .$cart_item_key.'<br><br>'. $cart_item['product_id']. '</div>'; 
     } 
     return $fragments; 
} 

Or:

function iconic_cart_count_fragments( $fragments ) {

     $cart = WC()->cart->get_cart();
     if (!empty($cart)) {
         foreach ( $cart as $cart_item_key => $cart_item )
            $output .= $cart_item_key. ' - ' . $cart_item['product_id'] . '<br>';
         $fragments['div.header-cart-count'] = '<div class="header-cart-count">' . $output . '</div>'; 
     }
     return $fragments; 
}