drupal_commerce - Skip shipping page on checkout flow

WE HAVE MOVED!

Please visit our new Drupal Website at https://www.xenyo.com我們的新網頁設計公司網頁.

/*
 * Implements hook_commerce_checkout_router()
 * Skip shipping page in checkout flow
 */
function MY_MODULE_commerce_checkout_router($order, $checkout_page) {
  if ($checkout_page['page_id'] == 'shipping') {
	//calculate shipping charge
	commerce_shipping_collect_rates($order);
 
	//update order status - @see commerce_checkout_form_submit
	$order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, TRUE, t('Shipping Page was skipped'));
 
	$form_state = array(
	  'order' => $order,
	  'checkout_page' => $checkout_page,
	  'rebuild' => FALSE,
	);
	$form_state['build_info']['args'][0] = $order;
	$form_state['build_info']['args'][1] = $checkout_page;
	$form_state['values']['commerce_shipping']['shipping_rates'] = $order->shipping_rates;
	foreach ($order->shipping_rates as $key => $shipping_method) {
	  if (empty($form_state['values']['commerce_shipping']['shipping_service'])) {
	    $form_state['values']['commerce_shipping']['shipping_service'] = $key;
	  }
	}
	$form = drupal_get_form('commerce_checkout_form_shipping', $order, $checkout_page);
 
	//run commerce_shipping_pane callback include validate and submit function
    commerce_checkout_form_validate($form, $form_state);
 
    drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
  }
}
Help Share this Article