Automattic\WooCommerce\StoreApi\Utilities
CartController::validate_cart_coupon()
Validates an existing cart coupon and returns any errors.
Метод класса: CartController{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->validate_cart_coupon( $coupon );
- $coupon(\WC_Coupon) (обязательный)
- Coupon object applied to the cart.
Код CartController::validate_cart_coupon() CartController::validate cart coupon WC 8.7.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 ); } }