Created
September 9, 2017 09:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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