Skip to content

Instantly share code, notes, and snippets.

@messica
Last active August 29, 2015 14:02
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 messica/791adda02d642deec023 to your computer and use it in GitHub Desktop.
Save messica/791adda02d642deec023 to your computer and use it in GitHub Desktop.
Track trials used in certain levels to disable those trials when "upgrading" to a new level with a trial.
<?php
/*
Plugin Name: PMPro Customizations
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Customizations for Paid Memberships Pro
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
// set Levels with free trials
global $levels_with_trials;
$levels_with_trials = array(1, 2, 4); //these are the membership level IDs with free trials
// track when a user signs up for a level with a free trial
function my_pmpro_after_change_membership_level($level_id, $user_id) {
global $levels_with_trials;
//are they checking out for one of the levels with a trial?
if(in_array($level_id, $levels_with_trials))
update_user_meta($user_id, 'pmpro_trial_used', 1); //track in user meta
}
add_action('pmpro_after_change_membership_level', 'my_pmpro_after_change_membership_level', 10, 2);
// remove trial from level if the user has already used a trial
function my_pmpro_checkout_level($level) {
global $current_user, $levels_with_trials;
//only do this for the specified levels
if(!in_array($level->id, $levels_with_trials))
return $level;
//if they already used the trial, disable it for this level
if(!empty($current_user->pmpro_trial_used))
$level->trial_limit = 0;
//return the new level
return $level;
}
add_filter('pmpro_checkout_level', 'my_pmpro_checkout_level');
//update level cost text if user has already used the trial
function my_pmpro_level_cost_text($cost, $level)
{
global $current_user, $levels_with_trials, $pmpro_currency_symbol;
//only do this for the specified levels
if(!in_array($level->id, $levels_with_trials))
return $cost;
//check if the trial has already been used
if(empty($current_user->pmpro_trial_used))
return $cost;
//remove trial from cost
$cost = "The price for membership is <strong>" . $pmpro_currency_symbol . $level->billing_amount . " per Month.";
return $cost;
}
add_filter("pmpro_level_cost_text", "my_pmpro_level_cost_text", 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment