Add an access callback to checkout panes

Created on 6 March 2012, over 13 years ago
Updated 4 July 2025, 29 days ago

This seems pretty ugly, it would be nice to have an access callback instead - unless there's a better way?

/**
 * Decide whether to display the organisation info pane.
 */
function ve_subscriptions_commerce_checkout_pane_info_alter(&$checkout_panes) {

  $subscription_type = NULL;
  $pane = 'commerce_fieldgroup_pane__group_organisation_details|commerce_order|commerce_order|form';
  $checkout_panes[$pane]['name'] = t('Organisation details');

  // Check we're in the process of checking out
  if (arg(0) === 'checkout' && is_numeric(arg(1)) && $order = commerce_order_load(arg(1))) {    

    // Load the order and verify it contains an organisation product
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    foreach ($wrapper->commerce_line_items as $product) {
      $subscription_type = $product->commerce_product->field_commerce_subscription_type->value();
      if ($subscription_type === 'organisation') {
        break;
      }
    }
 
    // If we don't have an organisation, disable the checkout pane.
    if ($subscription_type !== 'organisation') {
      $checkout_panes[$pane]['enabled'] = FALSE;
    }
  }
}
Feature request
Status

Closed: outdated

Version

1.0

Component

Developer experience

Created by

🇦🇺Australia aidanlis

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024