mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://github.com/strangerstudios/pmpro-snippets-library/blob/dev/frontend-pages/add-mycred-points-at-checkout.php
36 lines
1 KiB
Text
36 lines
1 KiB
Text
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 );
|