Drupal 7: Programmatically Accessing Commerce Line Item

In Drupal the function commerce_line_item_load() help us to load the commerce line item details Programmatically. The function accepts the unique id of each line item. The below syntax and example show how to access the line item details programmatically.


$lineItem = commerce_line_item_load(LINE_ITEM_ID); // Loading Line item object.
$attrib1 = $lineItem->ATTRIBUTE_1;
$attrib2 = $lineItem->ATTRIBUTE_2;


$lineItem = commerce_line_item_load(12345);
$itemLable = $lineItem->line_item_label; // Line Item label load.
$sku = $lineItem->line_item_sku; // Loading SKU.
$order_id = $lineItem->order_id; // Loading order Id.