-
-
Save andrewlimaza/0b99a1692353b39a7b442a156c90f642 to your computer and use it in GitHub Desktop.
Award MyCRED Points for membership check outs and renewals.
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
<?php | |
/** | |
* Add MyCRED points to whenever a user checksout for a PMPro Membership Level. | |
* Allows different points per membership level. | |
* Allows different points amount for membership renewals. | |
* Add this code below to your PMPro Customizations Plugin - http://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* MyCRED can be downloaded/configured here: https://wordpress.org/plugins/mycred/ | |
* Any questions, please feel free to visit www.paidmembershipspro.com | |
*/ | |
//MyCRED add points for certain levels. | |
function pmpro_add_mycred_points( $user_id, $morder ) { | |
global $wpdb; | |
//default values for myCred | |
$reference = 'pmpro_after_checkout'; | |
$point_amount = 5; | |
$entry = 'PMPro Registration/Renewal'; | |
$points_per_level = true; //set this to false to skip different points per level. | |
$points_for_renewal = true; //set this to false to skip different points for renewal. | |
$level_checkout = $_REQUEST['level']; //get what level a user is checking out for | |
//change values awarded for membership level checkout ( case value is equivalent to membership ID ) | |
if( $points_per_level ) { | |
switch ( $level_checkout ) { | |
case '1': | |
$point_amount = 15; | |
break; | |
case '2': | |
$point_amount = 20; | |
break; | |
case '3': | |
$point_amount = 100; | |
break; | |
} | |
} | |
if( $points_for_renewal ){ | |
//check if the user is renewing for a particular level | |
$sqlQuery = "SELECT membership_id FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . $user_id . "' ORDER BY timestamp DESC LIMIT 2"; | |
$res = $wpdb->get_results( $sqlQuery ); | |
//get second last order from user | |
$second_order = $res[1]->membership_id; | |
//assume a user is checking out for the same level (regardless of what level they are renewing) | |
if( !empty($second_order) ){ | |
if( $second_order === $level_checkout ){ | |
$point_amount = 500; | |
} | |
} | |
} | |
//add credits to mycred account. | |
mycred_add( $reference, $user_id, $point_amount, $entry ); | |
} | |
add_action( 'pmpro_after_checkout', 'pmpro_add_mycred_points', 10, 2 ); | |
// Update the Confirmation Message with MyCRED Balance | |
function pmpromyCRED_pmpro_confirmation_message( $message ) { | |
global $current_user; | |
if( !function_exists( 'pmpro_add_mycred_points' ) ){ | |
return $message; | |
} | |
$message .= '<hr /><h3>Points Awarded</h3>' . do_shortcode( '[mycred_history time="today" user_id="current"]' ) . '<hr />'; | |
return $message; | |
} | |
add_filter("pmpro_confirmation_message", "pmpromyCRED_pmpro_confirmation_message", 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment