Filter Uncanny Redemption Codes

ulc_codes_times_user_allowed_to_redeem

Filters whether a user is allowed to redeem codes, firing before redemption is processed.

add_filter( 'ulc_codes_times_user_allowed_to_redeem', $callback, 10, 1 );

Description

Filters the number of times a user can redeem a coupon. By default, users can redeem once unless multiple redemptions are enabled in settings. Developers can modify this return value to customize redemption limits per user.


Usage

add_filter( 'ulc_codes_times_user_allowed_to_redeem', 'your_function_name', 10, 1 );

Parameters

$codes_batch_id (mixed)
This parameter represents the default number of times a user is allowed to redeem a code from the given batch.

Return Value

The filtered value.


Examples

// Example: Limit redemption to a single time for specific code batches.
add_filter( 'ulc_codes_times_user_allowed_to_redeem', function( $allowed_redemptions, $codes_batch_id ) {
    // Define an array of code batch IDs that should have limited redemptions.
    $limited_redemption_batch_ids = array( 'batch-123', 'special-offer-xyz' );

    // Check if the current codes_batch_id is in our list of limited redemption batches.
    if ( in_array( $codes_batch_id, $limited_redemption_batch_ids, true ) ) {
        // If it is, force the user to be allowed only 1 redemption.
        return 1;
    }

    // Otherwise, return the original allowed redemptions value.
    return $allowed_redemptions;
}, 10, 2 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/helpers/class-database.php:1305
src/classes/helpers/class-database.php:1309

public static function number_of_times_a_user_allowed_to_redeem( $codes_batch_id = '' ) {
		if ( ! self::is_multiple_redemption_allowed( $codes_batch_id ) ) {
			return apply_filters( 'ulc_codes_times_user_allowed_to_redeem', 1, $codes_batch_id );
		}
		$number_times = AdminMenu::get_settings_value( Config::$uncanny_codes_times_code_can_be_reused, 1, is_multisite() );

		return apply_filters( 'ulc_codes_times_user_allowed_to_redeem', $number_times, $codes_batch_id );
	}


Scroll to Top