I want to remove billing and payment for free orders. Currently, I have the code below.

Am I safe to user global $user in this case? Is there any better way to get the user account & order involved when this hook runs?

I ask because, after installing this hook, I've seen payment and billing panes hidden under admin/commerce/config/checkout, but I didn't hide them there. This seems to be intermittent.

function MODULE_commerce_checkout_pane_info_alter(&$checkout_pane) {

  global $user;
  $order = commerce_cart_order_load($user->uid);
  if (!empty($order)) {

    //get the order wrapper and order total
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    $order_total = $order_wrapper->commerce_order_total->amount->value();

    // hide payment and billing info if the order total is <= 0
    if ((int) $order_total <= 0) {
      $checkout_pane['customer_profile_billing']['enabled'] = FALSE;
      $checkout_pane['commerce_payment']['enabled'] = FALSE;

1 Answer 1


You're seeing them hidden on the admin page because you're making no differentiation here in your code that would restrict the checkout pane info altering to only occur on checkout pages for customers, not administrators.

I'm divided. I recently created a checkout experience with an optional checkout pane, and I ultimately decided to alter the form directly instead of altering the checkout pane info. Part of it was that desire to ensure I had an identical definition on the front end / back end for all customers, but I'm not sure it was strictly necessary.

If you do end up altering the form instead, you need to supply new custom validate / submit handlers for the conditional checkout panes that wrap their default handlers and only invoke them if the pane was actually presented on a checkout form.

  • OK, makes sense. Just to confirm, when you say alter the form directly, do you mean using a standard form hook, like HOOK_form_alter? And do you know of a code example that shows the treatment of validate and submit handlers?
    – Dave Bruns
    Feb 6, 2014 at 3:46
  • Yes, that's what I mean. I'm not sure of any generic examples, but you're basically just implementing hook_commerce_checkout_pane_info_alter() and swapping out a value in the callbacks array. Feb 6, 2014 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.