WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Utilities

CartController::validate_cart_coupon() protected WC 1.0

Validates an existing cart coupon and returns any errors.

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

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->validate_cart_coupon( $coupon );
$coupon(WC_Coupon) (required)
Coupon object applied to the cart.

Code of CartController::validate_cart_coupon() WC 5.6.0

protected function validate_cart_coupon( \WC_Coupon $coupon ) {
	if ( ! $coupon->is_valid() ) {
		$cart = $this->get_cart_instance();
		$cart->remove_coupon( $coupon->get_code() );
		$cart->calculate_totals();
		throw new RouteException(
			'woocommerce_rest_cart_coupon_error',
			sprintf(
				/* translators: %1$s coupon code, %2$s reason. */
				__( 'The "%1$s" coupon has been removed from your cart: %2$s', 'woocommerce' ),
				$coupon->get_code(),
				wp_strip_all_tags( $coupon->get_error_message() )
			),
			409
		);
	}
}