WC_Cart::calculate_fees PHP Method

calculate_fees() public method

Calculate fees.
public calculate_fees ( )
    public function calculate_fees()
    {
        // Reset fees before calculation
        $this->fee_total = 0;
        $this->fees = array();
        // Fire an action where developers can add their fees
        do_action('woocommerce_cart_calculate_fees', $this);
        // If fees were added, total them and calculate tax
        if (!empty($this->fees)) {
            foreach ($this->fees as $fee_key => $fee) {
                $this->fee_total += $fee->amount;
                if ($fee->taxable) {
                    // Get tax rates
                    $tax_rates = WC_Tax::get_rates($fee->tax_class);
                    $fee_taxes = WC_Tax::calc_tax($fee->amount, $tax_rates, false);
                    if (!empty($fee_taxes)) {
                        // Set the tax total for this fee
                        $this->fees[$fee_key]->tax = array_sum($fee_taxes);
                        // Set tax data - Since 2.2
                        $this->fees[$fee_key]->tax_data = $fee_taxes;
                        // Tax rows - merge the totals we just got
                        foreach (array_keys($this->taxes + $fee_taxes) as $key) {
                            $this->taxes[$key] = (isset($fee_taxes[$key]) ? $fee_taxes[$key] : 0) + (isset($this->taxes[$key]) ? $this->taxes[$key] : 0);
                        }
                    }
                }
            }
        }
    }
WC_Cart