I have Drupal commerce checkout process where user choose shipping and in next step choose payment method.

I need data about chosen shipping in payment method form alter.

Is there any way how can i get info about chosen shipping in payment method form alter?


I have found solution.

global $user;
$order = commerce_cart_order_load($user->uid);
$line_items_ids = array();

// get all line items IDs
foreach($order->commerce_line_items as $line_item){
  $line_items_ids[] = $line_item["line_item_id"];

// load only "shipping" line items
$shipping_line_items = commerce_line_item_load_multiple(
  array('type' => 'shipping'),

I haven't found cleaner way how to do this. Hope it helps somebody. I still would be glad if anyone knows how to do this better.

| improve this answer | |
  • This is more or less what you need to do; however, a good feature request for the Shipping module would be to add an API function to make this easier. – Ryan Szrama Mar 23 '16 at 16:43

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.