Automattic\WooCommerce\StoreApi\Schemas\V1
CartSchema::get_totals()
Get total data.
Method of the class: CartSchema{}
No Hooks.
Return
Array
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_totals( $cart );
- $cart(\WC_Cart) (required)
- Cart class instance.
CartSchema::get_totals() CartSchema::get totals code WC 9.4.2
protected function get_totals( $cart ) { $has_calculated_shipping = $cart->show_shipping(); $decimals = wc_get_price_decimals(); return [ 'total_items' => $this->prepare_money_response( $cart->get_subtotal(), $decimals ), 'total_items_tax' => $this->prepare_money_response( $cart->get_subtotal_tax(), $decimals ), 'total_fees' => $this->prepare_money_response( $cart->get_fee_total(), $decimals ), 'total_fees_tax' => $this->prepare_money_response( $cart->get_fee_tax(), $decimals ), 'total_discount' => $this->prepare_money_response( $cart->get_discount_total(), $decimals ), 'total_discount_tax' => $this->prepare_money_response( $cart->get_discount_tax(), $decimals ), 'total_shipping' => $has_calculated_shipping ? $this->prepare_money_response( $cart->get_shipping_total(), $decimals ) : null, 'total_shipping_tax' => $has_calculated_shipping ? $this->prepare_money_response( $cart->get_shipping_tax(), $decimals ) : null, // Explicitly request context='edit'; default ('view') will render total as markup. 'total_price' => $this->prepare_money_response( $cart->get_total( 'edit' ), $decimals ), 'total_tax' => $this->prepare_money_response( $cart->get_total_tax(), $decimals ), 'tax_lines' => $this->get_tax_lines( $cart ), ]; }