Redirect if already bought (commerce_file)

Public
</> CopyGet raw version
php
  1. function YOUR_MODULE_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state, $form_id, $a1)
  2. {
  3. $form['#submit'][] = 'YOUR_MODULE_form_commerce_cart_add_to_cart_form_submit';
  4. $form['#validate'][] = 'YOUR_MODULE_form_commerce_cart_add_to_cart_form_validate';
  5. }
</> CopyGet raw version
php
  1. function YOUR_MODULE_form_commerce_cart_add_to_cart_form_validate($form, &$form_state)
  2. {
  3. if($line_item = $form_state['line_item']){
  4. $product = commerce_product_load($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']);
  5. $license = commerce_file_get_product_license($product);
  6. if(($license)&&(COMMERCE_LICENSE_ACTIVE == $license->status)){
  7. drupal_goto('my-purchases');
  8. }
  9. };
  10. }