WC_Cart::get_tax_totals()publicWC 1.0

Get taxes, merged by code, formatted ready for output.

Method of the class: WC_Cart{}

Return

Array.

Usage

$WC_Cart = new WC_Cart();
$WC_Cart->get_tax_totals();

WC_Cart::get_tax_totals() code WC 9.3.3

public function get_tax_totals() {
	$shipping_taxes = $this->get_shipping_taxes(); // Shipping taxes are rounded differently, so we will subtract from all taxes, then round and then add them back.
	$taxes          = $this->get_taxes();
	$tax_totals     = array();

	foreach ( $taxes as $key => $tax ) {
		$code = WC_Tax::get_rate_code( $key );

		if ( $code || apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) === $key ) {
			if ( ! isset( $tax_totals[ $code ] ) ) {
				$tax_totals[ $code ]         = new stdClass();
				$tax_totals[ $code ]->amount = 0;
			}

			$tax_totals[ $code ]->tax_rate_id = $key;
			$tax_totals[ $code ]->is_compound = WC_Tax::is_compound( $key );
			$tax_totals[ $code ]->label       = WC_Tax::get_rate_label( $key );

			if ( isset( $shipping_taxes[ $key ] ) ) {
				$tax -= $shipping_taxes[ $key ];
				$tax  = wc_round_tax_total( $tax );
				$tax += NumberUtil::round( $shipping_taxes[ $key ], wc_get_price_decimals() );
				unset( $shipping_taxes[ $key ] );
			}
			$tax_totals[ $code ]->amount          += wc_round_tax_total( $tax );
			$tax_totals[ $code ]->formatted_amount = wc_price( $tax_totals[ $code ]->amount );
		}
	}

	if ( apply_filters( 'woocommerce_cart_hide_zero_taxes', true ) ) {
		$amounts    = array_filter( wp_list_pluck( $tax_totals, 'amount' ) );
		$tax_totals = array_intersect_key( $tax_totals, $amounts );
	}

	return apply_filters( 'woocommerce_cart_tax_totals', $tax_totals, $this );
}