Forked from andrewlimaza/remove-custom-trial-for-members.php
Last active
April 16, 2025 06:02
-
-
Save JarrydLong/a7a800a51267a9f580d37e1578fd44b2 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)
This file contains hidden or 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 | |
/** | |
* 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->initial_payment = $level->billing_amount; // Set price to billing amount. | |
} | |
} | |
// 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