API: Add subtotal to orders response
This commit is contained in:
parent
497ec8186e
commit
b6dbaebe01
|
@ -119,6 +119,7 @@ class WC_API_Orders extends WC_API_Resource {
|
||||||
'status' => $order->status,
|
'status' => $order->status,
|
||||||
'currency' => $order->order_currency,
|
'currency' => $order->order_currency,
|
||||||
'total' => wc_format_decimal( $order->get_total(), 2 ),
|
'total' => wc_format_decimal( $order->get_total(), 2 ),
|
||||||
|
'subtotal' => wc_format_decimal( $this->get_order_subtotal( $order ), 2 ),
|
||||||
'total_line_items_quantity' => $order->get_item_count(),
|
'total_line_items_quantity' => $order->get_item_count(),
|
||||||
'total_tax' => wc_format_decimal( $order->get_total_tax(), 2 ),
|
'total_tax' => wc_format_decimal( $order->get_total_tax(), 2 ),
|
||||||
'total_shipping' => wc_format_decimal( $order->get_total_shipping(), 2 ),
|
'total_shipping' => wc_format_decimal( $order->get_total_shipping(), 2 ),
|
||||||
|
@ -377,4 +378,24 @@ class WC_API_Orders extends WC_API_Resource {
|
||||||
return new WP_Query( $query_args );
|
return new WP_Query( $query_args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get the order subtotal
|
||||||
|
*
|
||||||
|
* @since 2.1
|
||||||
|
* @param WC_Order $order
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
private function get_order_subtotal( $order ) {
|
||||||
|
|
||||||
|
$subtotal = 0;
|
||||||
|
|
||||||
|
// subtotal
|
||||||
|
foreach ( $order->get_items() as $item ) {
|
||||||
|
|
||||||
|
$subtotal += ( isset( $item['line_subtotal'] ) ) ? $item['line_subtotal'] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $subtotal;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue