Drupal 7: Programatically Delete a Commerece order

The function commerce_cart_order_load() help to load the current user cart details. Using the cart order object details we can able to unset or empty the commerce cart of that user. The function commerce_cart_order_empty() help to achieve this. The below sample code demonstrate how to delete cart of a user.

Syntax:
$cartDetails = commerce_cart_order_load(USER_ID); // Loding cart details.
commerce_cart_order_empty($cartDetails); // Unsetting cart.

Example:
global $user;
$cartDetails = commerce_cart_order_load($user->uid); // Loding cart details.
commerce_cart_order_empty($cartDetails); // Unsetting cart.

Category: