Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created October 31, 2019 11:23
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 kimcoleman/34d5ba06dfbcb2239ddb3c69be1d4f7a to your computer and use it in GitHub Desktop.
Save kimcoleman/34d5ba06dfbcb2239ddb3c69be1d4f7a to your computer and use it in GitHub Desktop.
Add myCred points at checkout based on membership level ID.
<?php
/**
* Add myCred points at checkout based on membership level ID.
* Optionally apply points only to members that select a recurring membership.
*
*/
function add_my_cred_to_pmpro_checkout( $user_id, $morder ) {
// Bail if myCred doesn't exist.
if ( ! function_exists( 'mycred_add' ) ) {
return;
}
// Get the user's level and expiration date.
$level = pmpro_getMembershipLevelForUser( $user_id );
$level_expiration = $level->enddate;
// Add these lines to give points to recurring members only.
if ( ! empty( $level->enddate ) ) {
return;
}
$points = 10; // default to 10 points. If level ID is blank 10 points would be awarded.
$reference = 'Successful Membership Payment';
$entry = 'Paid Memberships Pro - level: ' . $level->ID;
switch( $level->ID ) {
case 1:
$points = 20;
break;
case 2:
$points = 15;
break;
}
// Add points to myCred.
mycred_add( $reference, $user_id, $points, $entry );
// Write to order notes.
$morder->notes .= ' MyCred points for this order: ' . $points;
$morder->saveOrder();
}
add_action( 'pmpro_after_checkout', 'add_my_cred_to_pmpro_checkout', 10, 2 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Award MyCRED Points for Membership" at Paid Memberships Pro here: https://www.paidmembershipspro.com/award-mycred-points-membership-level-checkout/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment