You are here

function course_uc_form_alter in Course 6

Same name and namespace in other branches
  1. 8.3 modules/course_uc/course_uc.module \course_uc_form_alter()
  2. 8.2 modules/course_uc/course_uc.module \course_uc_form_alter()
  3. 7.2 modules/course_uc/course_uc.module \course_uc_form_alter()
  4. 7 modules/course_uc/course_uc.module \course_uc_form_alter()
  5. 3.x modules/course_uc/course_uc.module \course_uc_form_alter()

Implements hook_form_alter().

Hide the add to cart button when the user satisfied the requirement.

File

modules/course_uc/course_uc.module, line 8

Code

function course_uc_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'uc_product_add_to_cart') !== FALSE) {
    global $user;
    $node = node_load($form['nid']['#value']);
    if (course_node_is_course($node)) {
      $course = course_get_course($node, $user);
    }
    else {
      $courseNode = course_get_context('course_uc', 'payment', $node->nid);
      $course = course_get_course($courseNode, $user);
    }
    foreach ($course
      ->getObjects() as $idx => $courseObject) {
      if ($courseObject
        ->getComponent() == 'payment' && $courseObject
        ->getInstanceId() == $node->nid) {
        if ($courseObject
          ->getFulfillment()
          ->isComplete()) {
          $form['#access'] = FALSE;
        }
      }
    }
  }
}