Automattic\WooCommerce\StoreApi\Utilities
OrderController::validate_coupon_global_usage_limit
Check the coupon's global usage limit against the order.
Skipped once the order has recorded its own usage, so it is not counted against itself.
Метод класса: OrderController{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->validate_coupon_global_usage_limit( $coupon, $order ): void;
- $coupon(WC_Coupon) (обязательный)
- Coupon object applied to the order.
- $order(WC_Order) (обязательный)
- Order object.
Код OrderController::validate_coupon_global_usage_limit() OrderController::validate coupon global usage limit WC 11.2.2
protected function validate_coupon_global_usage_limit( \WC_Coupon $coupon, \WC_Order $order ): void {
$usage_limit = $coupon->get_usage_limit();
if ( ! $usage_limit || $order->get_recorded_coupon_usage_counts() ) {
return;
}
// Include tentative holds, matching WC_Discounts::validate_coupon_usage_limit().
$data_store = $coupon->get_data_store();
$tentative_usage = is_callable( array( $data_store, 'get_tentative_usage_count' ) )
? (int) $data_store->get_tentative_usage_count( $coupon->get_id() )
: 0;
if ( $coupon->get_usage_count() + $tentative_usage >= $usage_limit ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new Exception( $coupon->get_coupon_error( \WC_Coupon::E_WC_COUPON_USAGE_LIMIT_REACHED ) );
}
}