You are here

function commerce_registration_field_extra_fields_alter in Commerce Registration 7.2

Same name and namespace in other branches
  1. 7.3 commerce_registration.module \commerce_registration_field_extra_fields_alter()

Implements hook_field_extra_fields_alter().

File

./commerce_registration.module, line 637
Commerce Registration module code.

Code

function commerce_registration_field_extra_fields_alter(&$info) {

  // Loop through the product reference fields.
  foreach (commerce_info_fields('commerce_product_reference') as $field_name => $field) {
    foreach ($field['bundles'] as $entity_type => $bundles) {
      if ($entity_type == 'commerce_line_item' || $entity_type == 'commerce_product') {

        // Skip line items and products, don't want to remove these fields.
        continue;
      }
      foreach ($bundles as $bundle_name) {
        $product_fields = commerce_product_field_extra_fields();
        if (empty($product_fields['commerce_product'])) {

          // Skip if there are no commerce product extra fields.
          continue;
        }

        // Loop through each field on the product, and if it's a Registration,
        // hide it.
        foreach ($product_fields['commerce_product'] as $key => $value) {
          foreach ($value['display'] as $product_extra_field_name => $product_extra_field) {
            if ($product_extra_field['label'] == t('Registration')) {
              $tempfield =& $info[$entity_type][$bundle_name]['display']['product:' . $product_extra_field_name]['display'];
              foreach ($tempfield as $display => $settings) {
                $tempfield[$display]['visible'] = FALSE;
              }
            }
          }
        }

        // Loop through all field instances on products, and if each field is a
        // registration, hide it.
        foreach (field_info_instances('commerce_product') as $product_bundle_name => $product_fields) {
          foreach ($product_fields as $product_field_name => $product_field) {
            if ($product_field['label'] == t('Registration')) {
              $info[$entity_type][$bundle_name]['display']['product:' . $product_field_name]['configurable'] = FALSE;
              $info[$entity_type][$bundle_name]['display']['product:' . $product_field_name]['visible'] = FALSE;
              $info[$entity_type][$bundle_name]['display']['product:' . $product_field_name]['weight'] = 0;
            }
          }
        }
      }
    }
  }
}