Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created September 9, 2017 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielmerovingi/bf1b5c4c2d01fabe9c4d2a21b2967058 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/bf1b5c4c2d01fabe9c4d2a21b2967058 to your computer and use it in GitHub Desktop.
Give users bonus points when they buy points using the buyCRED add-on. Base the amount of bonus a user gets on their current rank.
/**
* Bonus Points
* Give users bonus points when they buy points using buyCRED
* based on their rank. Required us to know the Rank post ID for comparisons.
* @version 1.0
*/
function mycred_pro_buycred_bonus( $run_this, $mycred ) {
// Only applicable for point purchases via buyCRED and if the Ranks add-on is enabled
if ( substr( $run_this['ref'], 0, 15 ) != 'buy_creds_with_' || ! function_exists( 'mycred_get_users_rank_id' ) ) return $run_this;
extract( $run_this );
// Get the users current rank post ID
$users_rank_id = mycred_get_users_rank_id( $user_id, $type );
// Example: Newbee rank post ID 10
// If user has this rank, give the user 10 points more
if ( $users_rank_id == 10 )
$run_this['amount'] = $amount + 10;
// Example: Master rank post ID 12
// If user has this rank, give the user 100 points more
elseif ( $users_rank_id == 12 )
$run_this['amount'] = $amount + 100;
return $run_this;
}
add_filter( 'mycred_run_this', 'mycred_pro_buycred_bonus', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment