How can I e开发者_运维技巧mpty 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'; } }
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
精彩评论