How can I empty the cart from a php function using Ubercart ?
thanks
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';
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With