Automattic\WooCommerce\StoreApi\Schemas\V1\Agentic
CheckoutSessionSchema::format_line_items_from_cart
Format line items from cart.
Метод класса: CheckoutSessionSchema{}
Хуков нет.
Возвращает
Массив. Formatted line items.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->format_line_items_from_cart( $cart_items );
- $cart_items(массив) (обязательный)
- Cart items array.
Код CheckoutSessionSchema::format_line_items_from_cart() CheckoutSessionSchema::format line items from cart WC 11.0.1
protected function format_line_items_from_cart( $cart_items ) {
$items = [];
foreach ( $cart_items as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
$quantity = $cart_item['quantity'];
$base_amount = $this->amount_to_cents( $product->get_price() * $quantity );
$discount = $this->amount_to_cents( $cart_item['line_subtotal'] - $cart_item['line_total'] );
$subtotal = $base_amount - $discount;
$tax = $this->amount_to_cents( $cart_item['line_tax'] );
$total = $subtotal + $tax;
$items[] = [
'id' => (string) $cart_item_key,
'item' => [
'id' => (string) $product->get_id(),
'quantity' => $quantity,
],
'base_amount' => $base_amount,
'discount' => $discount,
'subtotal' => $subtotal,
'tax' => $tax,
'total' => $total,
];
}
return $items;
}