Add Remove products Button to Shopping Cart
Hello,
Everything is in the title.
How can I add a Remove products/Empty cart button in the Shopping Cart ?
Thanks a lot.
Ivelfan
By clicking any link on this page you are giving your consent for us to set cookies.
Comments
You can try create custom url
You can try create custom url to empty the cart 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');
}
Then on the shopping cart form/block you can make a new link using Views Custom Text to execute that custom empty link
Code Source from: http://drupal.stackexchange.com/questions/27491/empty-drupal-commerce-ca...
It´s also possible to change the form with form_alter
You do not have to add a URL. It is also possible to change the form
function YOURMODULE_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
case 'views_form_commerce_cart_form_default':
$form['actions']['clear_cart'] = array(
'#type' => 'submit',
'#value' => t('Emtpy cart'),
'#submit' => array('MYMODULE_empty_cart'),
);
break;
}}