Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

WC_Abstract_Order::hold_coupon_for_users( WC_Coupon $coupon, array $user_ids_and_emails, string $user_alias )

Hold coupon if usage limit per customer is defined.


Description Description


Parameters Parameters

$coupon

(Required) Coupon object.

$user_ids_and_emails

(Required) Array of user Id and emails to check for usage limit.

$user_alias

(Required) User ID or email to use to record current usage.


Top ↑

Return Return

(string) Meta key which indicates held coupon.


Top ↑

Source Source

File: includes/abstracts/abstract-wc-order.php

	private function hold_coupon_for_users( $coupon, $user_ids_and_emails, $user_alias ) {
		$result = $coupon->get_data_store()->check_and_hold_coupon_for_user( $coupon, $user_ids_and_emails, $user_alias );
		if ( false === $result ) {
			// translators: Actual coupon code.
			throw new Exception( sprintf( __( 'An unexpected error happened while applying the Coupon %s.', 'woocommerce' ), esc_html( $coupon->get_code() ) ) );
		} elseif ( 0 === $result ) {
			// translators: Actual coupon code.
			throw new Exception( sprintf( __( 'You have used this coupon %s in another transaction during this checkout, and coupon usage limit is reached. Please remove the coupon and try again.', 'woocommerce' ), esc_html( $coupon->get_code() ) ) );
		}
		return $result;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.