Automattic\WooCommerce\StoreApi\Utilities

CartController::validate_cart_coupons()publicWC 1.0

Validate all coupons in the cart and check for errors.

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

Хуков нет.

Возвращает

null. Ничего.

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

$CartController = new CartController();
$CartController->validate_cart_coupons();

Код CartController::validate_cart_coupons() WC 7.1.0

public function validate_cart_coupons() {
	$cart_coupons = $this->get_cart_coupons();
	$errors       = [];

	foreach ( $cart_coupons as $code ) {
		$coupon = new \WC_Coupon( $code );
		try {
			$this->validate_cart_coupon( $coupon );
		} catch ( RouteException $error ) {
			$errors[] = new WP_Error( $error->getErrorCode(), $error->getMessage(), $error->getAdditionalData() );
		}
	}

	if ( ! empty( $errors ) ) {

		$error = new WP_Error();
		foreach ( $errors as $wp_error ) {
			$error->merge_from( $wp_error );
		}

		throw new InvalidCartException(
			'woocommerce_coupons_error',
			$error,
			409
		);
	}
}