Automattic\WooCommerce\StoreApi\Schemas\V1

OrderSchema::get_totals()protectedWC 1.0

Get total data.

Method of the class: OrderSchema{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_totals( $order );
$order(\WC_Order) (required)
Order instance.

OrderSchema::get_totals() code WC 9.5.1

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' ) )
		),
	];
}