WC_REST_Orders_V1_Controller::prepare_line_items()
Create or update a line item.
Метод класса: WC_REST_Orders_V1_Controller{}
Хуков нет.
Возвращает
WC_Order_Item_Product
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->prepare_line_items( $posted, $action );
- $posted(массив) (обязательный)
- Line item data.
- $action(строка)
- 'create' to add line item or 'update' to update it.
По умолчанию: 'create'
Код WC_REST_Orders_V1_Controller::prepare_line_items() WC REST Orders V1 Controller::prepare line items WC 9.6.0
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; }