WordPress at a glance
function is not described

WC_REST_Orders_V1_Controller::prepare_line_items() protected WC 1.0

Create or update a line item.

{} It's a method of the class: WC_REST_Orders_V1_Controller{}

No Hooks.

Return

WC_Order_Item_Product.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_line_items( $posted, $action );
$posted(array) (required)
Line item data.
$action(string)
'create' to add line item or 'update' to update it.

Code of WC_REST_Orders_V1_Controller::prepare_line_items() WC 5.0.0

<?php
protected function prepare_line_items( $posted, $action = 'create' ) {
	$item    = new WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' );
	$product = wc_get_product( $this->get_product_id( $posted, $action ) );

	if ( $product && $product !== $item->get_product() ) {
		$item->set_product( $product );

		if ( 'create' === $action ) {
			$quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1;
			$total    = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) );
			$item->set_total( $total );
			$item->set_subtotal( $total );
		}
	}

	$this->maybe_set_item_props( $item, array( 'name', 'quantity', 'total', 'subtotal', 'tax_class' ), $posted );

	return $item;
}