WC_Cart_Totals::calculate_totals()
Main cart totals.
Method of the class: WC_Cart_Totals{}
Hooks from the method
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->calculate_totals();
Changelog
Since 3.2.0 | Introduced. |
WC_Cart_Totals::calculate_totals() WC Cart Totals::calculate totals code WC 9.5.1
protected function calculate_totals() { $this->set_total( 'total', NumberUtil::round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + array_sum( $this->get_merged_taxes( true ) ), 0 ) ); $items_tax = array_sum( $this->get_merged_taxes( false, array( 'items' ) ) ); // Shipping and fee taxes are rounded separately because they were entered excluding taxes (as opposed to item prices, which may or may not be including taxes depending upon settings). $shipping_and_fee_taxes = NumberUtil::round( array_sum( $this->get_merged_taxes( false, array( 'fees', 'shipping' ) ) ), wc_get_price_decimals() ); $this->cart->set_total_tax( $items_tax + $shipping_and_fee_taxes ); // Allow plugins to hook and alter totals before final total is calculated. if ( has_action( 'woocommerce_calculate_totals' ) ) { do_action( 'woocommerce_calculate_totals', $this->cart ); } // Allow plugins to filter the grand total, and sum the cart totals in case of modifications. $this->cart->set_total( max( 0, apply_filters( 'woocommerce_calculated_total', $this->get_total( 'total' ), $this->cart ) ) ); }