I would like ot be able to set a custom line item title to appear where ever the line item appears. I have taken a look at https://drupal.org/node/1029956 but I cannot see how to implement exactly what I am after. I need to be able to set a title for the line item that is not the product title, or has additional information to the product title. I have hacked commerce_product_line_item_title for now in order to get it to do what I need but I am sure there is a better way to do this.
TIA
function commerce_product_line_item_title($line_item) {
// Currently, just return the product's title. However, in the future replace
// this with the product preview build mode.
if ($product = entity_metadata_wrapper('commerce_line_item', $line_item)->commerce_product->value()) {
- return check_plain($product->title);
+ $alt_title = isset($line_item->data['newtitle']) ? $line_item->data['newtitle'] : '';
+ return check_plain($product->title) . $alt_title;
}
}
Comments
Comment #1
rszrama commentedYou should be able to use hook_commerce_line_item_type_info_alter() to set a different title callback function that includes your code.
Comment #2
kurtfoster commentedthx rszrama, much easier than I thought. I found the info for the function here hook_commerce_line_item_type_info_alter .
I had a read through the source on this page as well, commerce_line_item.api.php, to get more info on how to add the callback.
I can now add an item to the data array on my line item to either override or append to the product title. My code is below.
Comment #3
rszrama commentedGreat, glad you got it working. Just make sure that that svbtitle has been sanitized before printing it out like this! : )
Comment #4
johnhanley commentedThanks @kurtfoster. Your code example of how to override a line item title on the order edit page saved me time (even 4+ years later).
Comment #5
rszrama commentedThat's awesome, John! : D