Enforce per user coupon usage limit for guest user checkout.
In a previous commit, a regression was introduced where we were no longer checking for usage limit of guest user in an install. This commit adds back that check.
This commit is contained in:
parent
f8bb7681b6
commit
8adb474149
|
@ -1476,6 +1476,16 @@ class WC_Cart extends WC_Legacy_Cart {
|
|||
$coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_NOT_YOURS_REMOVED );
|
||||
$this->remove_coupon( $code );
|
||||
}
|
||||
|
||||
$coupon_usage_limit = $coupon->get_usage_limit_per_user();
|
||||
if ( 0 < $coupon_usage_limit && 0 === get_current_user_id() ) {
|
||||
// For guest, usage per user has not been enforced yet. Enforce it now.
|
||||
$coupon_data_store = $coupon->get_data_store();
|
||||
$billing_email = strtolower( sanitize_email( $billing_email ) );
|
||||
if ( $coupon_data_store && $coupon_data_store->get_usage_by_email( $coupon, $billing_email ) >= $coupon_usage_limit ) {
|
||||
$coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_USAGE_LIMIT_REACHED );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue