WordPress at Your Fingertips
function is not described

WC_Order_Item::calculate_taxes() public WC 3.2.0

Calculate item taxes.

{} It's a method of the class: WC_Order_Item{}

Return

true|false. True if taxes were calculated.

Usage

$WC_Order_Item = new WC_Order_Item();
$WC_Order_Item->calculate_taxes( $calculate_tax_for );
$calculate_tax_for(array)
Location data to get taxes for. Required.
Default: array()

Changelog

Since 3.2.0 Introduced.

Code of WC_Order_Item::calculate_taxes() WC 5.7.0

public function calculate_taxes( $calculate_tax_for = array() ) {
	if ( ! isset( $calculate_tax_for['country'], $calculate_tax_for['state'], $calculate_tax_for['postcode'], $calculate_tax_for['city'] ) ) {
		return false;
	}
	if ( '0' !== $this->get_tax_class() && 'taxable' === $this->get_tax_status() && wc_tax_enabled() ) {
		$calculate_tax_for['tax_class'] = $this->get_tax_class();
		$tax_rates                      = WC_Tax::find_rates( $calculate_tax_for );
		$taxes                          = WC_Tax::calc_tax( $this->get_total(), $tax_rates, false );

		if ( method_exists( $this, 'get_subtotal' ) ) {
			$subtotal_taxes = WC_Tax::calc_tax( $this->get_subtotal(), $tax_rates, false );
			$this->set_taxes(
				array(
					'total'    => $taxes,
					'subtotal' => $subtotal_taxes,
				)
			);
		} else {
			$this->set_taxes( array( 'total' => $taxes ) );
		}
	} else {
		$this->set_taxes( false );
	}

	do_action( 'woocommerce_order_item_after_calculate_taxes', $this, $calculate_tax_for );

	return true;
}