public/wordpress/wp-content/plugins/wp-courseware/includes/controllers/cart.php
/**
	 * Check for user coupons (now that we have billing email). If a coupon is invalid, add an error.
	 *
	 * Checks two types of coupons:
	 *  1. Where a list of customer emails are set (limits coupon usage to those defined).
	 *  2. Where a usage_limit_per_user is set (limits coupon usage to a number based on user ID and email).
	 *
	 * @since 4.5.0
	 *
	 * @param array $posted Post data.
	 */
Check for user coupons (now that we have billing email). If a coupon is invalid, add an error.
Checks two types of coupons:
1. Where a list of customer emails are set (limits coupon usage to those defined).
2. Where a usage_limit_per_user is set (limits coupon usage to a number based on user ID and email).



@param array $posted Post data.
Check for user coupons ( now that we have billing email ) . If a coupon is invalid add an error . Checks two types of coupons : 1 . Where a list of customer emails are set ( limits coupon usage to those defined ) . 2 . Where a usage_limit_per_user is set ( limits coupon usage to a number based on user ID and email ) . @param array $posted Post data .
public function check_customer_coupons( $posted ) {
		foreach ( $this->get_applied_coupons() as $code ) {
			$coupon = wpcw_get_coupon_by_code( $code );
			if ( $coupon->is_valid() ) {
				$current_user = wp_get_current_user();
				$check_emails = array_unique(
					array_filter(
						array_map(
							'strtolower', array_map(
								'sanitize_email', array(
									$posted['email'],
									$current_user->user_email,
								)
							)
						)
					)
				);
				$limit_per_user = $coupon->get_usage_limit_per_user();
				if ( 0 < $limit_per_user ) {
					$used_by         = $coupon->get_used_by();
					$usage_count     = 0;
					$user_id_matches = array( get_current_user_id() );
					foreach ( $check_emails as $check_email ) {
						$usage_count       += count( array_keys( $used_by, $check_email, true ) );
						$user              = get_user_by( 'email', $check_email );
						$user_id_matches[] = $user ? $user->ID : 0;
					}
					foreach ( $user_id_matches as $user_id ) {
						$usage_count += count( array_keys( $used_by, (string) $user_id, true ) );
					}
					if ( $usage_count >= $coupon->get_usage_limit_per_user() ) {
						$coupon->add_coupon_error( Coupon::E_COUPON_USAGE_LIMIT_REACHED );
						$this->remove_coupon( $code );
					}
				}
			}
		}
	}
public function check_customer_coupons ( $ posted ) { foreach ( $ this -> get_applied_coupons ( ) as $ code ) { $ coupon = wpcw_get_coupon_by_code ( $ code ) ; if ( $ coupon -> is_valid ( ) ) { $ current_user = wp_get_current_user ( ) ; $ check_emails = array_unique ( array_filter ( array_map ( 'strtolower' , array_map ( 'sanitize_email' , array ( $ posted [ 'email' ] , $ current_user -> user_email , ) ) ) ) ) ; $ limit_per_user = $ coupon -> get_usage_limit_per_user ( ) ; if ( 0 < $ limit_per_user ) { $ used_by = $ coupon -> get_used_by ( ) ; $ usage_count = 0 ; $ user_id_matches = array ( get_current_user_id ( ) ) ; foreach ( $ check_emails as $ check_email ) { $ usage_count += count ( array_keys ( $ used_by , $ check_email , true ) ) ; $ user = get_user_by ( 'email' , $ check_email ) ; $ user_id_matches [ ] = $ user ? $ user -> ID : 0 ; } foreach ( $ user_id_matches as $ user_id ) { $ usage_count += count ( array_keys ( $ used_by , ( string ) $ user_id , true ) ) ; } if ( $ usage_count >= $ coupon -> get_usage_limit_per_user ( ) ) { $ coupon -> add_coupon_error ( Coupon :: E_COUPON_USAGE_LIMIT_REACHED ) ; $ this -> remove_coupon ( $ code ) ; } } } } }
Check for user coupons (now that we have billing email).
Check for user coupons ( now that we have billing email ) .
// Get user and posted emails to compare. // Usage limits per user - check against billing and user email and user ID. // Check usage against emails.