How to hide checkout panes based on shipping method?
I have 4 shipping methods(Flat rate) and 2 custom shipping information panes(Commerce Fieldgroup Panes).
So I am trying to do something like this:
1. Method one - Show default shipping information pane, hide other shipping information panes.
2. Method two - Show custom shipping information pane for Method two and hide other shipping information panes.
3. Method three - Show custom shipping information pane for Method three and hide other shipping information panes.
4. Method four - Hide all shipping information panes.
How to do it?
As I understand, there is no option to use rules for hiding and showing panes based on shipping method? I think, it is very much needed functionality. Why do write custom module for simple task like this if I could do it with rules?
As I can't use rules for this functionality, I try to do it with custom module, but my programming skills are not good enough for this.
I hoped to get this code working, but no luck:
Code from: http://drupal.org/node/1285902
<?php
/*
* Hook hook_commerce_checkout_pane_info_alter($checkout_pane)
*/
function mymodule_commerce_checkout_pane_info_alter(&$checkout_pane) {
global $user;
// $checkout_pane actually holds ALL the panes...
foreach($checkout_pane as $pane_name => &$pane_data) {
// ...we only need to override one of them
if($pane_name == 'customer_profile_shipping' && $pane_data['enabled']) {
// load current order
$order = commerce_cart_order_load($user->uid);
// array $order->data was detected with dsm()
// it doesn't contain anything except 'shipping_method' string element
// rules_pick_up is the ID of a cloned flat_rate shipping method
if($order->data['shipping_method'] == 'flat_rate|rules_pick_up') {
// the pane is enabled by default, so we need to disable it
$pane_data['enabled'] = 0;
}
}
}
}
?>
It gives me error:
Notice: Undefined index: shipping_method in mymodule_commerce_checkout_pane_info_alter() (line 34 of ............./sites/all/modules/mymodule/mymodule.module). Backtrace:
mymodule_commerce_checkout_pane_info_alter(Array, NULL, NULL) module.inc:1022
drupal_alter('commerce_checkout_pane_info', Array) commerce_checkout.module:494
commerce_checkout_panes(Array) commerce_checkout.module:402
commerce_checkout_pages() commerce_checkout.module:287
commerce_checkout_commerce_order_status_info()
call_user_func_array('commerce_checkout_commerce_order_status_info', Array) module.inc:823
module_invoke_all('commerce_order_status_info') commerce_order.module:1103
commerce_order_statuses(Array) commerce_cart.module:678
commerce_cart_order_is_cart(Object) commerce_cart.module:534
commerce_cart_commerce_order_load(Array)
call_user_func_array('commerce_cart_commerce_order_load', Array) entity.inc:334
DrupalDefaultEntityController->attachLoad(Array, ) commerce_order.controller.inc:121
CommerceOrderEntityController->attachLoad(Array, ) entity.inc:204
DrupalDefaultEntityController->load(Array, Array) common.inc:7623
entity_load('commerce_order', Array, Array, ) commerce_order.module:775
commerce_order_load_multiple(Array, Array) commerce_order.module:744
commerce_order_load('1') menu.inc:592
_menu_load_objects(Array, Array) menu.inc:759
_menu_translate(Array, Array) menu.inc:471
menu_get_item() menu.inc:1751
menu_get_custom_theme(1) menu.inc:1766
menu_set_custom_theme() common.inc:5043
_drupal_bootstrap_full() bootstrap.inc:2186
drupal_bootstrap(7) index.php:20
Can you please help me get this code working or write better one? :)
Comments
I just added commerce coupon and that throw my number off as well. Just another FYI to watch out for.