Submitted by blaine on Fri, 12/14/2012 - 11:08

While working on a Drupal Commerce project for a client, which will be handling products and donations will also need to handle conference registrations. There is a commerce_registration module which is looking like a very nice contribution and should work well. The commerce registration module adds a new page to the checkout process for the custom registration fields that are mapped for the selected item being purchased.

There does not appear to be a way to not show this page in the checkout workflow even if it's not required which is clearly not desired. We tried to disable a checkout pane using hook_commerce_checkout_pane_info_alter() but even when you unset the registration pane, an empty page will still appear with just the continue to next page button. According to the drupal commerce  API reference, there is also a hook_commerce_checkout_page_info_alter but while you can remove the registration page from the checkout workflow, it was not possible to obtain any context like the order or cart contents to determine if the page should be removed or not. 

The commerce checkout APIs also includes the hook_commerce_checkout_router which allows you to alter the checkout workflow where you have context available, so you are able to check the order or cart and determine if you should redirect the checkout process.

The following code the final working function that will skip the registration page if not required.

 * Implements hook_commerce_checkout_router().
 * Skip the registration checkout page unless required.
function pi_commerce_commerce_checkout_router($order, $checkout_page) {
  global $user;
  if ($checkout_page['page_id'] == 'registration' && $user->uid) {
    $registration_required = FALSE;
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
      $line_item = $line_item_wrapper->value();
      if ($line_item->line_item_label == 'Conference Attendee') {
        $registration_required = TRUE;
    if (!$registration_required) {
      $order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, TRUE, t('Conference Registration was skipped - not required for these products.'));
      drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);


General Tags