API: Add subtotal to orders response

This commit is contained in:
Max Rice 2014-01-13 22:13:48 -05:00
parent 497ec8186e
commit b6dbaebe01
1 changed files with 21 additions and 0 deletions

View File

@ -119,6 +119,7 @@ class WC_API_Orders extends WC_API_Resource {
'status' => $order->status,
'currency' => $order->order_currency,
'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_tax' => wc_format_decimal( $order->get_total_tax(), 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 );
}
/**
* 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;
}
}