Automattic\WooCommerce\Internal\Orders

TaxesController::calc_line_taxes()publicWC 1.0

Calculate line taxes programmatically.

Метод класса: TaxesController{}

Хуков нет.

Возвращает

Объект. The retrieved order object.

Использование

$TaxesController = new TaxesController();
$TaxesController->calc_line_taxes( $post_variables ): object;
$post_variables(массив) (обязательный)
Contents of the $_POST array that would be passed in an Ajax call.

Код TaxesController::calc_line_taxes() WC 8.7.0

public function calc_line_taxes( array $post_variables ): object {
	$order_id           = absint( $post_variables['order_id'] );
	$calculate_tax_args = array(
		'country'  => isset( $post_variables['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $post_variables['country'] ) ) ) : '',
		'state'    => isset( $post_variables['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $post_variables['state'] ) ) ) : '',
		'postcode' => isset( $post_variables['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $post_variables['postcode'] ) ) ) : '',
		'city'     => isset( $post_variables['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $post_variables['city'] ) ) ) : '',
	);

	// Parse the jQuery serialized items.
	$items = array();
	parse_str( wp_unslash( $post_variables['items'] ), $items );

	// Save order items first.
	wc_save_order_items( $order_id, $items );

	// Grab the order and recalculate taxes.
	$order = wc_get_order( $order_id );
	$order->calculate_taxes( $calculate_tax_args );
	$order->calculate_totals( false );

	return $order;
}