जवाबों:
कोड कुछ इस तरह दिखेगा:
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');
}
I know this is an old thread, but there is now a module for this see Commerce Empty Cart Paths. This module allows site administrators to define multiple paths, and when a user visits a non-declared page, their shopping cart is emptied.
As suggested, try Commerce Empty Cart Paths module.
It allows site administrators to define multiple paths, and when a user visits a non-declared page, their shopping cart is emptied.
Usage:
- Download and enable the module.
- Go to admin/commerce/config/empty-cart-paths and enter any additional paths. checkout, checkout/, cart and cart/ are declared by default.
Or combert's sandbox: Commerce Clear Cart module which simply adds a page that when visited will empty the current users Commerce cart. It also adds a link to that page to the Commerce cart view.
I hope this helps someone having the same issue... I installed Path Rules https://www.drupal.org/project/pathrules. From there create a custom rule... 1. Event ->Drupal is initializing 2. check path cart/empty 3. Actions: Remove all products from an order 4. goto Parameter: URL: [site:url]