1

I would like to add a column on the line item table on the orders edit page. I've tried to use theme_registry_alter($theme_registry) to override the commerce line item theme_commerce_line_item_manager, but it seems like it's not working. Below is my code:-

function MODULE_theme_registry_alter($theme_registry) {
  if (isset($theme_registry['commerce_line_item_manager'])) {  
    $theme_registry['commerce_line_item_manager']['theme path'] = drupal_get_path('module', 'MODULE');
    $theme_registry['commerce_line_item_manager']['function'] = 'MODULE_commerce_line_item_manager';
  }
}

function MODULE_commerce_line_item_manager(&$variables) {
  return 'Print something';
}

Am I missing something? Or is there any other way to alter the display or add a new column on the table?

I've also created a patch, but I don't feel it's the solution to alter the display. Please help. Thank you in advance.

1

If you want to add an editable column, you cannot do that just through the theme layer (though I think the same would hold true even for a non-editable column). Instead you need to alter the form element that gets created, even if it's just through an order edit form level alteration. First you need to create the elements you need in the form array and then you can override the theme function to ensure they get rendered into the table in the right column.

You should also look up documentation on how to override theme functions in general. You shouldn't need to alter the theme registry, just place the theme function in your theme's template.php, copy the functionality of the default theme function, and alter it to your need.

  • Hi Ryan, Thank you so much for responding. I just need to display the stock available on each line item. I'll try to alter it using my theme and will get back if I succeed. – Madelyn Cruz Feb 14 '17 at 2:00
  • Sounds good; you'll basically need to copy the normal theme function and then put your stock value code in the area where we drupal_render() different form elements into the line item table. I do still think you'll need a form alter, though, to stuff the appropriate stock value in the form array rather than trying to load it in the theme layer. – Ryan Szrama Feb 15 '17 at 14:37

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.