Home Forums How-to Questions Limit Total Number of Points a User Can Earn

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #7078
    mecray

    Hi again. (Last question, I promise!)

    Can I set a maximum number of points a user can earn? I only want my users to be able to earn 1,000 points all time. In other words, once they reach 1,000 points, they cannot earn any more even if they redeem points to drop below 1,000.

    Hope that makes sense.

    Thanks again…as always. We’re opening up our library’s Summer Reading program tomorrow, and everyone is very excited. I couldn’t have done it without this plugin!

    (Do you have a way to donate some funds to your cause?)

    #7080
    WPExperts

    Hey.

    You can use the mycred_add filter to enforce a max.
    Here is an example:

    add_filter( 'mycred_add', 'mycred_pro_user_max', 999, 3 );
    function mycred_pro_user_max( $reply, $request, $mycred ) {
    
    	// Ignore if allready declined
    	if ( $reply === false ) return $reply;
    
    	extract( $request );
    
    	// Ignore deductions
    	if ( $amount < $mycred->zero() ) return $reply;
    
    	// Get uses balance
    	$balance = $mycred->get_users_balance( $user_id, $type );
    
    	// Maximum
    	$max = 1000;
    	
    	// Check if we already reched max
    	if ( $balance >= $max ) return false;
    
    	// Else check if adding this up will exceed max
    	if ( $balance + $amount >= 1000 ) return false;
    
    	// all else return default
    	return $reply;
    
    }
    

    Just add the code snippet to your themes functions.php file and change the max amount to a number that works for you and you are set.

    You can “donate” by purchasing tokens if you do not find anything you want in the store. You can purchase token by clicking on the array in the blue menu on the top right corner of the screen and selecting “Buy Tokens” in the dropdown menu.

    #7083
    mecray

    Thanks again. Just purchased some tokens as a thanks.

    #21449
    Godwin

    Hi ,
    what of if you want minimum balance to be zero, hence no user should have negative point

    #21461
    WPExperts
    #78834
    Pe Xo

    Hello, I would like to refresh the topic a bit. How to limit the number of points scored for a given user? Where can I put a username or id in the code to limit earnings? So that I can get a maximum of e.g. 600 points?

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
11