Drupal 7: Check given user Cart have items or not

We will add the product to the cart to checkout. The below is the code which used to check current user cart have the product or not. The function "commerce_line_items_quantity()" will returns the total quantity and "commerce_line_items_total()" will return cart total. These functions are taking the order line item array. This code will return an array of product that user have been added to his/her cart.

Sample Code: 

global $user;
$quantity = 0;
$total = 0;
// Load the order based on user.
$order = commerce_cart_order_load($user->uid);
if ($order) {
  $wrapper = entity_metadata_wrapper('commerce_order', $order);
  $line_items = $wrapper->commerce_line_items;
  // Get the line item quantity from cart based on user.
  $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
  $total = commerce_line_items_total($line_items);
}
print $quantity; // Total quantity of the cart.
print $total; // Total amount for current cart.
Category: