I rewrite this code for Drupal 6
<?php
function uc_empty_cart_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'uc_cart_view_form') {
// Remove "Update button" from form
// unset($form['update']);
// Add "Empty cart" button to form
$form['empty'] = array(
'#type' => 'submit',
'#value' => t('Empty cart'),
);
// Add new submit handler for the "Empty cart" button,
// then call the default submit handler to deal with the
// rest of the form
$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'):
// Take action to empty the cart
uc_cart_empty(uc_cart_get_id());
drupal_set_message(t('Cart is now empty...'));
// set redirect
$form_state['redirect'] = 'cart';
}
}
?>Also I create module UC_EMPTY_CART
| Attachment | Size |
|---|---|
| uc_empty_cart.zip | 6.79 KB |
