Last active
September 14, 2017 14:30
-
-
Save gabrielmerovingi/4272a03150e71266e2150f88f3d48e28 to your computer and use it in GitHub Desktop.
Charge a custom fee based on a users myCRED rank when making a transfer in myCRED.
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
/** | |
* Custom transfer Fees | |
* Charge a custom fee based on a users myCRED rank when making | |
* a transfer in myCRED. | |
* @version 1.0 | |
*/ | |
function mycred_pro_transfer_fee_by_rank( $fee, $amount, $user_id, $point_type, $prefs ) { | |
// Make sure the rank add-on is enabled to prevent crashes | |
if ( ! function_exists( 'mycred_get_rank_object_id' ) ) return $fee; | |
$users_rank_id = mycred_get_rank_object_id( $user_id ); | |
// Make sure the user has a rank | |
if ( $users_rank_id !== false ) { | |
// If users has the rank with the ID of 12, impose 10% fee | |
if ( $users_rank_id == 12 ) | |
$fee = $amount * 0.1; | |
// Else if user has the rank with the ID of 13, impose 25% fee | |
elseif ( $users_rank_id == 13 ) | |
$fee = $amount * 0.25; | |
} | |
return $fee; | |
} | |
add_filter( 'mycred_pt_get_fee', 'mycred_pro_transfer_fee_by_rank', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment