Automattic\WooCommerce\StoreApi\Utilities
CartController::validate_cart_coupons()
Validate all coupons in the cart and check for errors.
Method of the class: CartController{}
No Hooks.
Return
null
. Nothing (null).
Usage
$CartController = new CartController(); $CartController->validate_cart_coupons();
CartController::validate_cart_coupons() CartController::validate cart coupons code WC 9.2.3
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 ); } }