Skip A Custom Checkout Page So I thought I had been pretty clever when in the code for a custom checkout pane, in a custom checkout page, I did this:

function checkout_pane_giftaid_pane_checkout_form($form, &amp;$form_state, $checkout_pane, $order) {
  if($showPane==1){
    //show something awesome
  }
  else {
    $checkout_pages = commerce_checkout_pages();
    commerce_order_status_update($order,'checkout_payment');
    $url = 'checkout/'. $order-&gt;order_number  . '/' . $checkout_pages['gift-aid']['next_page'];
    drupal_goto($url);
  }
}


If showPane is equal to 1 it displays the Pane's content, if not it directs you to the next checkout page. This however has presented an issue because I have two custom checkout pages.

The result of this is if you are on 'custom page 2' and press 'Go Back' it goes back to the previous page ('custom page 1'), but if $showPane=0 on this page then the else statement means its set to forward. So a user hits 'go back' on 'custom page 2' and what they see, is this page reload (actually it has gone back to 'custom page 1' where it is told to go to the next page, 'custom page 2').

So my question is this: clearly I have not gone about 'skipping' custom checkout pages in the right way, how would I do it properly?
You can use hook_commerce_checkout_router() to skip Commerce Checkout pages.

See the advanced example here: Skipping a Commerce Checkout page in the checkout workflow

/**
 * Implements hook_commerce_checkout_router().
 *
 * Skip the registration checkout page unless required.
 */
function MYMODULE_commerce_checkout_router($order, $checkout_page) {
  global $user;

  if ($checkout_page['page_id'] == 'registration' &amp;&amp; $user-&gt;uid) {
    $registration_required = FALSE;
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    foreach ($order_wrapper-&gt;commerce_line_items as $line_item_wrapper) {
      $line_item = $line_item_wrapper-&gt;value();
      if ($line_item-&gt;line_item_label == 'Conference Attendee') {
        $registration_required = TRUE;
        break;
      }
    }
    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-&gt;order_id . '/' . $checkout_page['next_page']);
    }
  }
}