5

I have used the following module to add a custom checkout pane to get some additional information from the user regarding the order.

https://drupal.org/project/commerce_fieldgroup_panes

I now need to apply a condition that if the order contain a product of specific product type then display this pane else hide it.

Can some one please guide me how can I do this.

I have found the following code from https://drupal.org/node/1807092 but I don't know how to modify it according my need. Looking for some help on how to modify & use this code.

<?php function commerce_conditional_panes_commerce_checkout_pane_info_alter(&$checkout_panes, $form, &$form_state) {
global $user;
foreach($checkout_panes as $pane_name => &$pane_data) {
    // load current order
    $order = commerce_cart_order_load($user->uid);
    // retrieve the value of controlling field
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    $control = $order->field_make['und']['0']['value'];
    // Perform switch to see what to do with each aircraft make
    switch ($control)
    {
       case "value1":
         break;
       case "value2":
         break;
       case "value3":
         break;
       case "value4":
         break;
       case "value5":
         break;
       case "value6":
         // ...we only need to override one of them
         if($pane_name == 'commerce_fieldgroup_pane__conditional_pane' && $pane_data['enabled']) {
           // the pane is enabled by default, so we need to disable it
           $pane_data['enabled'] = 0;
         }
         break;
       case "value6":
         break;
       case "value7":
         break;
       case "value8":
         break;
       default:
         break;
       }
    }
}
?>
6

It's surely too late for your project... Anyway, you may use Commerce Rules Extra, it adds the exact features you need :

  • Rules conditions : Total product of type quantity comparison : Total of products of specified type and with a specified quantity
  • Rules actions : Change pane properties : Change visibility, page, weight of a pane

Once you installed it, in checkout settings , set your pane as disabled by default and create a new rule

  • event: Process checkout pane
  • conditions: Total product of type quantity comparison
    • Parameter: Order: [commerce_order]
    • Product Type: YOUR PRODUCT TYPE
    • Operator: >, Quantity: 0
  • action : Change pane properties
    • Parameter: Id of pane to change: YOUR PANE
    • Enabled: true
    • move to : checkout
0

Kojo's answer will no longer work as the 'Commerce Rules Extra' no longer can be used to hide panes.

See: https://www.drupal.org/node/2083981#comment-9740753

"Looks like hook_commerce_order_view_alter doesn't exist anymore, you are right" - Perignon (module maintainer)

  • You should write here the most important link text, because your answer can be flaged as low quality. – Adrian Cid Almaguer Jul 12 '17 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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