I want to offer 2 shipping options: a real one (flat rate) and "in store pick up" which obviously doesn't require the shipping address.

Is there any way to enable/disable the "shipping profile" checkout pane using just some custom shipping method code? I couldn't find a useful example on how to do it so I'm kinda stuck.

Currently I can unconditionally disable the pane using hook_commerce_checkout_pane_info_alter($checkout_pane) but i don't know how to lookup the shipping method that was selected (shipping profile pane is on the 'review' page, shipping is at 'checkout').

function mymodule_commerce_checkout_pane_info_alter(&$checkout_pane) {
    if(<strong>$no_actual_shipping_needed</strong>) {
	$checkout_pane['customer_profile_shipping']['enabled'] = 0;
    }
}

I need some directions, please.

CommentFileSizeAuthor
checkout-settings-screen.jpg30.69 KBscoff

Comments

scoff’s picture

Ok, here's the working code, but I'm not sure if it's the best way possible. Also I'm not sure how dependable is that $order->data['shipping_method'].

/*
 * 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 works if the shipping profile pane is on a separate checkout page that appears after the shipping method is set.

googletorp’s picture

Status: Active » Fixed

Closing

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

UrmasZ’s picture

I can't get this code working:

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

And I am not smart enough to fix it. Can someone help? :)

Having option to hide panes based on shipping method is so much needed functionality!

googletorp’s picture

#4 Try to Q&A section on drupalcommerce.org

switch13’s picture