Automattic\WooCommerce\StoreApi\Schemas\V1

OrderSchema::get_totalsprotectedWC 1.0

Get total data.

Метод класса: OrderSchema{}

Хуков нет.

Возвращает

Массив.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_totals( $order );
$order(WC_Order) (обязательный)
Order instance.

Код OrderSchema::get_totals() WC 10.5.0

protected function get_totals( $order ) {
	return [
		'subtotal'           => $this->prepare_money_response( $order->get_subtotal() ),
		'total_discount'     => $this->prepare_money_response( $order->get_total_discount() ),
		'total_shipping'     => $this->prepare_money_response( $order->get_total_shipping() ),
		'total_fees'         => $this->prepare_money_response( $order->get_total_fees() ),
		'total_tax'          => $this->prepare_money_response( $order->get_total_tax() ),
		'total_refund'       => $this->prepare_money_response( $order->get_total_refunded() ),
		'total_price'        => $this->prepare_money_response( $order->get_total() ),
		'total_items'        => $this->prepare_money_response(
			array_sum(
				array_map(
					function( $item ) {
						return $item->get_total();
					},
					array_values( $order->get_items( 'line_item' ) )
				)
			)
		),
		'total_items_tax'    => $this->prepare_money_response(
			array_sum(
				array_map(
					function( $item ) {
						return $item->get_tax_total();
					},
					array_values( $order->get_items( 'tax' ) )
				)
			)
		),
		'total_fees_tax'     => $this->prepare_money_response(
			array_sum(
				array_map(
					function( $item ) {
						return $item->get_total_tax();
					},
					array_values( $order->get_items( 'fee' ) )
				)
			)
		),
		'total_discount_tax' => $this->prepare_money_response( $order->get_discount_tax() ),
		'total_shipping_tax' => $this->prepare_money_response( $order->get_shipping_tax() ),
		'tax_lines'          => array_map(
			function( $item ) {
				return [
					'name'  => $item->get_label(),
					'price' => $this->prepare_money_response( $item->get_tax_total() ),
					'rate'  => strval( $item->get_rate_percent() ),
				];
			},
			array_values( $order->get_items( 'tax' ) )
		),
	];
}