Automattic\WooCommerce\StoreApi\Utilities
CartController::validate_cart_coupon
Validates an existing cart coupon and returns any errors.
Method of the class: CartController{}
No Hooks.
Returns
null. Nothing (null).
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.
CartController::validate_cart_coupon() CartController::validate cart coupon code WC 10.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. */
esc_html__( '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
);
}
}