Last active
          October 12, 2015 20:58 
        
      - 
      
- 
        Save ss81/4086579 to your computer and use it in GitHub Desktop. 
    Only one product in shopping cart.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| /** | |
| * Implementation of hook_form_alter() | |
| */ | |
| function hook_form_alter(&$form, $form_state, $form_id) { | |
| if (drupal_match_path($form_id, 'uc_product_add_to_cart_form_*')) { | |
| array_unshift($form['#submit'], 'uc_product_before_add_to_cart_submit'); | |
| } | |
| } | |
| /** | |
| * Callback, which clears shopping cart if it's not empty. | |
| * Next submit callback (provided by ubercart) will add new product into shopping cart. | |
| */ | |
| function uc_product_before_add_to_cart_submit($form, &$form_state) { | |
| $cart_items = uc_cart_get_contents(); | |
| if (!empty($cart_items)) { | |
| uc_cart_empty(uc_cart_get_id(FALSE)); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment