3 replies [Last post]
IT Guy 3000's picture
Offline
Joined: 05/11/2009
Juice: 121

Hi all,

I'd like to prevent checkout completion (at the "review order" stage) if the country is not U.S. and a certain product class or any of a set of SKU's are in the cart. I'm a PHP noob, so wondering if this can be done via admin/conditional actions. If not, some head-start on the PHP required and where it would go would be terrific.

Thanks much,
ITG3000

IT Guy 3000's picture
Offline
Joined: 05/11/2009
Juice: 121
Re: Prevent Checkout for International Shipping Address based on

Giving this question a little bump. Is there any existing functionality that allows evaluation of cart contents to determine if checkout is permitted? Seems that any number of products have export restrictions and this would be useful. And more elegant than just some checkout text that says "We can only ship [product] in the U.S" or similar. Thanks all.

Docc's picture
Offline
Getting busy with the Ubercode.
Joined: 07/03/2008
Juice: 168
Re: Re: Prevent Checkout for International Shipping Address base

Take a look at this module
http://drupal.org/project/uc_ship2country

k4ml's picture
Offline
Joined: 05/29/2010
Juice: 4
Prevent checkout

I looked around for some way to prevent users from checkout if they do not have certain roles and product in their cart. My case a bit different, I'm building a site where we sale a sport event. User must first purchase a membership and then grant role as a member. They are allowed to add stuff into their cart even they do not purchase a membership or a member yet but must be prevented from checkout ie - when they click Checkout button, a message must be displayed that they must be a member or added the membership product in their cart.

Since I can't find any existing solutions, I ended up doing some code, basically some hook_form_alter and custom validate function. Here it is:-

<?php
function custom_cart_form_alter(&$form, &$form_state, $form_id) {
  if (
$form_id == 'uc_cart_view_form') {
   
$form['#validate'][] = 'custom_cart_view_form_validate';
  }
}

function

custom_cart_view_form_validate(&$form, &$form_state) {
  global
$user;
 
$values = $form_state['values'];
 
$membership_nid = variable_get('custom_membership_nid', 339);
 
$has_membership = FALSE;

 

$op = strtolower($form_state['clicked_button']['#value']);
  if (
$op == 'checkout') {
    if (!
in_array('custom member', $user->roles)) {
      foreach (
$values['items'] as $item) {
        if (
$item['nid'] == $membership_nid) {
         
$has_membership = TRUE;
          break;
        }
      }
    }
    else {
     
$has_membership = TRUE;
    }

    if (!

$has_membership) {
     
form_set_error('', 'You must be a custom member or added the membership in your cart');
    }
  }
}
?>