Drupal 7: Programmatically update Commerce Line Item

In Drupal Commerce is an entity reference to the order during order creation. The line item will refer the product in the order. We can able to programmatically update the line item using the function "entity_metadata_wrapper()". The below example will show how to update the line items programmatically. 


$lineItem = commerce_line_item_load(LINE_ITEM_ID);
$lineItemWrapper = entity_metadata_wrapper('commerce_line_item', $lineItem);
$lineItemWrapper->PRPERTY_1 = NEW_VALUE; 
$lineItemWrapper->PRPERTY_2 = NEW_VALUE;
$lineItemWrapper->PRPERTY_3 = NEW_VALUE;


$lineItem = commerce_line_item_load(1004922);
$lineItemWrapper = entity_metadata_wrapper('commerce_line_item', $lineItem);
$lineItemWrapper->quantity = 2; // Updating Quantity of lineitem.
$price['amount'] = 1800; 
$lineItemWrapper->commerce_unit_price = $price; // Line item base amount update.