Drupal - empty drupal commerce cart with a url?

The code would look something like this:

function MYMODULE_menu() {
  $items['cart/empty'] = array(
    'title' => 'Empty Cart',
    'access arguments' => array('access content'), // or whatever permission you want
    'page callback' => 'MYMODULE_empty_cart',
    'type' => MENU_CALLBACK
  );

  return $items;
}

function MYMODULE_empty_cart() {
  global $user;
  // Load the order and empty the cart
  $order = commerce_cart_order_load($user->uid);
  commerce_cart_order_empty($order);

  // As this page won't display anything you need to redirect somewhere
  drupal_goto('some/page');
}

Tags:

7

Commerce