Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created September 14, 2017 14:27
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/e4c1da23f2b0c11de7d75100609262b3 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/e4c1da23f2b0c11de7d75100609262b3 to your computer and use it in GitHub Desktop.
Charge a custom fee based on a users WordPress role when making a transfer in myCRED.
/**
* Custom transfer Fees
* Charge a custom fee based on a users WordPress role when making
* a transfer in myCRED.
* @version 1.0
*/
function mycred_pro_transfer_fee_by_role( $fee, $amount, $user_id, $point_type, $prefs ) {
// if we are just a subscriber, impose 10% fee
if ( ! user_can( $user_id, 'publish_posts' ) )
$fee = $amount * 0.1;
// else if we are an "contributor", impose 5% fee
elseif ( ! user_can( $user_id, 'delete_published_posts' ) )
$fee = $amount * 0.05;
// everyone else pays no fee
else $fee = 0;
return $fee;
}
add_filter( 'mycred_pt_get_fee', 'mycred_pro_transfer_fee_by_role', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment