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 andrewlimaza/ebfe3230647aefa2b7a34227677e6004 to your computer and use it in GitHub Desktop.
Save andrewlimaza/ebfe3230647aefa2b7a34227677e6004 to your computer and use it in GitHub Desktop.
Remove custom trial for levels for existing and past members Paid Memberships Pro (Trial only used once)
<?php
/**
* Removes custom trial for active and past members.
* Adjust this code accordingly to price your membership level when removing the trial.
* To add this code to your site, please follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_remove_custom_trial( $level ) {
if ( is_admin() || ! is_user_logged_in() ) {
return $level;
}
// Instantiate a new MemberOrder object.
$order = new MemberOrder();
$lastOrder = $order->getLastMemberOrder(null, array('success', 'cancelled'));
// They were once a past member, or currently have a level. Let's remove the trial for any level.
if ( $lastOrder || pmpro_hasMembershipLevel() ) {
// remove trial limit and set initial price to the billing amount.
if ( $level->billing_amount > 0 && $level->trial_limit > 0 ) {
$level->initial_payment = $level->billing_amount; // Set price to billing amount.
$level->trial_limit = 0; // Remove the trial setting
}
}
// Return the modified level object.
return $level;
}
add_action( 'pmpro_checkout_level', 'my_pmpro_remove_custom_trial' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment