Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubercart: how to empty the cart?

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

thanks

like image 941
aneuryzm Avatar asked Dec 09 '22 12:12

aneuryzm


1 Answers

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';   
  }
}
like image 180
Ran Bar-Zik Avatar answered Jan 08 '23 08:01

Ran Bar-Zik