I am using the Ubercart module for my site. And I need to set Minimum order subtotal pragmatically not for admin panel. I am going to create a custom module to apply this condition but not getting any hook.

Any suggestions?


If you would like to validate minimum subtotal directly in the cart, you could use hook_form_alter.

function mymodule_form_alter(&$form, &$form_state, $form_id){
  switch ($form_id) {
    case 'uc_cart_view_form':
      //add own validate function
      $form['#validate'] = array('mymodule_subtotal_validate');

Then define the content of the validation function:

function mymodule_subtotal_validate($form, &$form_state){
  //validate only if we are going to submit the cart form 
  //there are others possibilites, when the validate handler is called,
  //such as quantity change, etc..)
  if(isset($_POST['op']) && $_POST['op'] == t('Checkout')){
    //access cart items and their quantity
    $sum = 0;
    foreach($form_state['values']['items'] as $key => $item){
      $product = node_load($item['nid']);
      $qty = $item['qty'];
      $sum += $product->price * $qty;

    if($sum < YOUR_SUM){
      form_set_error(null, 'Your items subtotal is less than minimal subtotal.');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.