Multiple Recurring Payouts Types
-
Is there a way to set it so I can add multiple Recurring Payouts. I need this functionality for the 3 tiers of monthly subscribers on our site, whom each should be given daily points based on their tier.
Membership Tier 1 100 Points Daily
Membership Tier 2 200 Points Daily
Membership Tier 3 500 Points DailyIs there already way to do this buy adding additional recurring payouts in the back end and limiting each payout based on user roles (created with Paid Memberships Pro).
-
We have actually migrated now to s2members now I am told.
Hi.
If you are using myCRED 1.6 or higher then you could always adjust how much points each user gets when the payout occurs using the mycred_run_this filter.
Here is a quick example using the default WordPress capabilities.
add_filter( 'mycred_run_this', 'mycred_pro_payout_by_role' ); function mycred_pro_payout_by_role( $request ) { // Only applicable for recurring payouts if ( $request['ref'] != 'recurring_payout' ) return $request; // Get user id $user_id = absint( $request['user_id'] ); // Administrators get 100 points if ( user_can( $user_id, 'edit_users' ) ) $request['amount'] = 100; // Editors get 50 points elseif ( user_can( $user_id, 'edit_others_posts' ) ) $request['amount'] = 50; // Everyone else gets the amount set in the service return $request; }You could instead of checking capabilities check a users role or anything else that you need. I unfortunately have no s2 members knowledge so I am not sure how they differentiate between accounts.
Awesome, would i be putting this in my functions.php?
s2members just creates new roles with custom capabilities, however they seem to act and display just like regular wordpress roles.
Let me see if i understand your example.
if ( $request['ref'] != 'recurring_payout' ) return $request;
this checks to see if a recurring payout is to be made.$user_id = absint( $request['user_id'] );
this would retrieve the users ID (does this include their role?)// Administrators get 100 points if ( user_can( $user_id, 'edit_users' ) ) $request['amount'] = 100; // Editors get 50 points elseif ( user_can( $user_id, 'edit_others_posts' ) ) $request['amount'] = 50; // Everyone else gets the amount set in the service return $request;these set what each level of subscriber/moderator would earn in myCRED points.
However I seek to set points payouts on roles, not specific User ID, or is the ID section pulling their membership level as well and then comparing?.
Hey.
The first part:
if ( $request['ref'] != 'recurring_payout' ) return $request;makes sure that the code only is applied to recurring payouts and nothing else. Without this, your change will run for every single instance where users get points.
Next:
$user_id = absint( $request['user_id'] );this just grabs the users ID. The ID in itself does not contain your users role. For that, you will need to grab the entire user object and then check the role of the user.
$user_id = absint( $request['user_id'] ); $user = get_userdata( $user_id );Now you have a users roles accessable under $user->roles (which is an array).
So you could check for example:
if ( in_array( 'subscriber', $user->roles ) ) $request['amount'] = 100; elseif ( in_array( 'administrator', $user->roles ) ) $request['amount'] = 500;I have HACKED my own code together, but i am NOT a programmer, so let me know if this is even close.
add_filter( 'mycred_run_this', 'mycred_pro_payout_by_role' ); function mycred_pro_payout_by_role( $request ) { // Only applicable for recurring payouts if ( $request['ref'] != 'recurring_payout' ) return $request; // Get user role $user_role = absint( $request['user_role'] ); // Set various roles recurring points payouts. // ADMIN get 0 points if ($user_role == 'administrator') { $request['amount'] = 0; // Lvl-1 get 100 points } elseif ($user_role == 'Subscriber-Slug-Lvl-1') { $request['amount'] = 100; // Lvl-2 get 200 points } elseif ($user_role == 'Subscriber-Slug-Lvl-2') { $request['amount'] = 200; // Lvl-3 get 500 points } elseif ($user_role == 'Subscriber-Slug-Lvl-3') { $request['amount'] = 500; // Lvl-4 get 1000 points } elseif ($user_role == 'Subscriber-Slug-Lvl-4') { $request['amount'] = 1000; // Everyone else gets the amount set in the service } else { return $request; }Hmm in regards to your most recent post i think my first attempt is VERY wrong lol
How about this:
add_filter( 'mycred_run_this', 'mycred_pro_payout_by_role' ); function mycred_pro_payout_by_role( $request ) { // Only applicable for recurring payouts if ( $request['ref'] != 'recurring_payout' ) return $request; // Get user role $user_id = absint( $request['user_id'] ); $user = get_userdata( $user_id ); // Set various roles recurring points payouts. // ADMIN get 0 points if ( in_array( 'administrator', $user->roles ) ) $request['amount'] = 0; // Subscriber Basic get 10 points elseif ( in_array( 'subscriber', $user->roles ) ) $request['amount'] = 10; // Subscriber LVL 1 get 100 points elseif ( in_array( 'subscriber-lvl-1', $user->roles ) ) $request['amount'] = 100; // Subscriber LVL 2 get 200 points elseif ( in_array( 'subscriber-lvl-2', $user->roles ) ) $request['amount'] = 200; // Subscriber LVL 3 get 500 points elseif ( in_array( 'subscriber-lvl-3', $user->roles ) ) $request['amount'] = 500; // Subscriber LVL 4 get 1000 points elseif ( in_array( 'subscriber-lvl-4', $user->roles ) ) $request['amount'] = 1000; // Everyone else gets the amount set in the service } else { return $request; }Looks good but you have missed the last closing bracket and since this is a filter, you must always return a result. Your code will only return a result if none of those roles are found which will break your site.
Here is how it should be: http://pastebin.com/KZGdH1B4
cool, and this should be added to functions.php correct?
Yes.
The topic ‘Multiple Recurring Payouts Types’ is closed to new replies.