WordPress at a glance
function is not described

WC_REST_Orders_Controller::calculate_coupons() protected WC 1.0

Calculate coupons.

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

No Hooks.

Return

true/false.

Usage

// protected - for code of main (parent) or child class
$result = $this->calculate_coupons( $request, $order );
$request(WP_REST_Request) (required)
Request object.
$order(WC_Order) (required)
Order data.

Code of WC_REST_Orders_Controller::calculate_coupons() WC 5.0.0

<?php
protected function calculate_coupons( $request, $order ) {
	if ( ! isset( $request['coupon_lines'] ) || ! is_array( $request['coupon_lines'] ) ) {
		return false;
	}

	// Remove all coupons first to ensure calculation is correct.
	foreach ( $order->get_items( 'coupon' ) as $coupon ) {
		$order->remove_coupon( $coupon->get_code() );
	}

	foreach ( $request['coupon_lines'] as $item ) {
		if ( is_array( $item ) ) {
			if ( empty( $item['id'] ) ) {
				if ( empty( $item['code'] ) ) {
					throw new WC_REST_Exception( 'woocommerce_rest_invalid_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 );
				}

				$results = $order->apply_coupon( wc_clean( $item['code'] ) );

				if ( is_wp_error( $results ) ) {
					throw new WC_REST_Exception( 'woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400 );
				}
			}
		}
	}

	return true;
}