Automattic\WooCommerce\StoreApi\Schemas\V1
CartSchema::get_tax_lines
Get tax lines from the cart and format to match schema.
Method of the class: CartSchema{}
No Hooks.
Returns
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() CartSchema::get tax lines code WC 10.8.1
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;
}