Automattic\WooCommerce\StoreApi\Schemas\V1

CartSchema::get_tax_lines()protectedWC 1.0

Get tax lines from the cart and format to match schema.

Method of the class: CartSchema{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_tax_lines( $cart );
$cart(\WC_Cart) (required)
Cart class instance.

CartSchema::get_tax_lines() code WC 8.7.0

protected function get_tax_lines( $cart ) {
	$tax_lines = [];

	if ( 'itemized' !== get_option( 'woocommerce_tax_total_display' ) ) {
		return $tax_lines;
	}

	$cart_tax_totals = $cart->get_tax_totals();
	$decimals        = wc_get_price_decimals();

	foreach ( $cart_tax_totals as $cart_tax_total ) {
		$tax_lines[] = array(
			'name'  => $cart_tax_total->label,
			'price' => $this->prepare_money_response( $cart_tax_total->amount, $decimals ),
			'rate'  => WC_Tax::get_rate_percent( $cart_tax_total->tax_rate_id ),
		);
	}

	return $tax_lines;
}