Skip to content

Instantly share code, notes, and snippets.

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 eighty20results/bfea877e9ae5ff3af5c401c5604f3c6f to your computer and use it in GitHub Desktop.
Save eighty20results/bfea877e9ae5ff3af5c401c5604f3c6f to your computer and use it in GitHub Desktop.
Place a PMPro member in another level when they cancel.
<?php
/*
Plugin Name: Eighty/20 Results: Assign free level when cancelling
Plugin URI: https://eighty20results.com/paid-memberships-pro/do-it-for-me/
Description: Custom code to configure a default member level for a user who cancels
Version: 1.0
Requires at least: 4.5
Tested up to: 4.9.8
Author: Eighty / 20 Results by Wicked Strong Chicks, LLC <thomas@eighty20results.com>
Author URI: https://eighty20results.com/thomas-sjolshagen/
License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
License: GPLv2 or later
*/
/**
* Set the membership level ID your member should be assigned when they cancel
*/
if (! defined('PMPRO_DOWNGRADE_TARGET' ) ) {
define( 'PMPRO_DOWNGRADE_TARGET', 1 ); // TODO: Change to the correct membership level ID
}
/**
* Change membership level when the user's membership is cancelled/expired
*
* @param int $level_id
* @param int $user_id
*/
function pmpro_after_change_membership_level_default_level($level_id, $user_id) {
// If we see this global set, then another gist is planning to give the user their level back
global $pmpro_next_payment_timestamp;
if ( ! empty( $pmpro_next_payment_timestamp ) ) {
return;
}
if ( 0 == $level_id ) {
// Actually cancelling, give them PMPRO_DOWNGRADE_TARGET membership level instead
pmpro_changeMembershipLevel( PMPRO_DOWNGRADE_TARGET, $user_id);
}
}
add_action("pmpro_after_change_membership_level", "pmpro_after_change_membership_level_default_level", 999, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment