aneuryzm
aneuryzm

Reputation: 64844

Ubercart: how to empty the cart?

How can I empty the cart from a php function using Ubercart ?

thanks

Upvotes: 4

Views: 4522

Answers (2)

Nick
Nick

Reputation: 31

There's also a Drupal-Ubercart module to do this. From any of your product nodes, click the "Features" tab, add the ubercart-tweaks feature and radio to empty cart when purchased.

http://drupal.org/project/uc_atctweaks

Upvotes: 3

Ran Bar-Zik
Ran Bar-Zik

Reputation: 1237

uc_cart_empty(uc_cart_get_id());

If you want to add 'empty cart button' use this code:

function uc_empty_cart_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'uc_cart_view_form') {
$form['empty'] = array(
      '#type' => 'submit',
      '#value' => t('Empty Cart'),
    );

    $form['#submit'][] = 'uc_empty_cart_cart_view_form_submit';
  }
}
function

uc_empty_cart_cart_view_form_submit($form, &$form_state) {
  switch ($form_state['values']['op']) {
    case t('Empty cart'):
      uc_cart_empty(uc_cart_get_id());
      $form_state['redirect'] = 'cart';   
  }
}

Upvotes: 11

Related Questions