I need to add a column(a "checking logistics picking" link) to each line item on order page(i.e. user/%user/orders/%commerce_order page), but I cannot make it done. I tried hook_entity_view_alter and hook_block_view_alter, but seems they can only alter order entity view, cannot alter line items part of the order.

How to alter line item on order page? It became urgent, please help! Thanks.

  • I am trying hook_views_post_execute, $view->result[0]->field_field_end_date[0]['rendered']['#markup'] = ..., but it's not displayed on the page. I guess I miss something. I see commerce_line_item.views_default.inc, but I don't know what should I do to alter the handler.
    – Jack Zhou
    Commented Mar 30, 2015 at 12:37

1 Answer 1


I know it is a bit late, but here is what I did to modify the line items on an order view.

For my example, I wanted the type field to be displayed, so I altered the view of the commerce_line_item entity using hook_views_pre_view(&$view). Here the code that have:

switch ($view->name) {
    case 'commerce_line_item_table':
        $view->display['default']->handler->options['fields']['type']['exclude'] = FALSE;

This is all I needed to do since type was already there in the commerce_line_item_table view defined in commerce_line_item.views_default.inc, but if you want to add a field to the view, it would look something like this

        $view->display['default']->handler->options['fields']['type']['id'] = 'type'; 
        $view->display['default']->handler->options['fields']['type']['table'] = 'commerce_line_item';          
        $view->display['default']->handler->options['fields']['type']['field'] = 'type';
        $view->display['default']->handler->options['fields']['type']['relationship'] = 'commerce_line_items_line_item_id';             

Please note, that when you later the view for the user/%user/orders/%commerce_order page, it also alters admin/commerce/orders/%commerce_order/view since they both use entity_view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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