WC_Abstract_Order::calculate_taxes │ public │ WC 1.0

Calculate taxes for all line items and shipping, and store the totals and tax rows.

If by default the taxes are based on the shipping address and the current order doesn't have any, it would use the billing address rather than using the Shopping base location.

Will use the base country unless customer addresses are set.

Method of the class: WC_Abstract_Order{}

Returns

void. Nothing (null).

Usage

$WC_Abstract_Order = new WC_Abstract_Order();
$WC_Abstract_Order->calculate_taxes( $args );
$args(array)
Added in 3.0.0 to pass things like location.
Default: array()

WC_Abstract_Order::calculate_taxes() code WC 11.1.2

public function calculate_taxes( $args = array() ) {
	do_action( 'woocommerce_order_before_calculate_taxes', $args, $this );

	$calculate_tax_for  = $this->get_tax_location( $args );
	$shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );

	if ( 'inherit' === $shipping_tax_class ) {
		$found_classes      = array_intersect( array_merge( array( '' ), WC_Tax::get_tax_class_slugs() ), $this->get_items_tax_classes() );
		$shipping_tax_class = count( $found_classes ) ? current( $found_classes ) : false;

		// Orders without product line items have no tax class to inherit, so use the standard class.
		if ( false === $shipping_tax_class && 0 === count( $this->get_items() ) ) {
			$shipping_tax_class = '';
		}
	}

	$is_vat_exempt = apply_filters( 'woocommerce_order_is_vat_exempt', 'yes' === $this->get_meta( 'is_vat_exempt' ), $this );

	// Trigger tax recalculation for all items.
	foreach ( $this->get_items( array( 'line_item', 'fee' ) ) as $item_id => $item ) {
		if ( ! $is_vat_exempt ) {
			$item->calculate_taxes( $calculate_tax_for );
		} else {
			$item->set_taxes( false );
		}
	}

	foreach ( $this->get_shipping_methods() as $item_id => $item ) {
		if ( false !== $shipping_tax_class && ! $is_vat_exempt ) {
			$item->calculate_taxes( array_merge( $calculate_tax_for, array( 'tax_class' => $shipping_tax_class ) ) );
		} else {
			$item->set_taxes( false );
		}
	}

	$this->update_taxes();
}