WC_Abstract_Order::hold_coupon_for_users()
Hold coupon if usage limit per customer is defined.
Method of the class: WC_Abstract_Order{}
No Hooks.
Return
String
. Meta key which indicates held coupon.
Usage
// private - for code of main (parent) class only $result = $this->hold_coupon_for_users( $coupon, $user_ids_and_emails, $user_alias );
- $coupon(WC_Coupon) (required)
- Coupon object.
- $user_ids_and_emails(array) (required)
- Array of user Id and emails to check for usage limit.
- $user_alias(string) (required)
- User ID or email to use to record current usage.
WC_Abstract_Order::hold_coupon_for_users() WC Abstract Order::hold coupon for users code WC 8.7.0
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; }