WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Utilities

OrderController::validate_coupon_usage_limit() protected WC 1.0

Check usage restrictions of a coupon against the order.

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

No Hooks.

Return

null. Nothing.

Usage

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

Code of OrderController::validate_coupon_usage_limit() WC 5.8.0

protected function validate_coupon_usage_limit( \WC_Coupon $coupon, \WC_Order $order ) {
	$coupon_usage_limit = $coupon->get_usage_limit_per_user();

	if ( $coupon_usage_limit > 0 ) {
		$data_store  = $coupon->get_data_store();
		$usage_count = $order->get_customer_id() ? $data_store->get_usage_by_user_id( $coupon, $order->get_customer_id() ) : $data_store->get_usage_by_email( $coupon, $order->get_billing_email() );

		if ( $usage_count >= $coupon_usage_limit ) {
			throw new Exception( $coupon->get_coupon_error( \WC_Coupon::E_WC_COUPON_USAGE_LIMIT_REACHED ) );
		}
	}
}