Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active September 2, 2022 09:51
Show Gist options
  • Save andrewlimaza/100e79ce3eece2e14844ea6552b80362 to your computer and use it in GitHub Desktop.
Save andrewlimaza/100e79ce3eece2e14844ea6552b80362 to your computer and use it in GitHub Desktop.
Remove subscription delay for existing members [Paid Memberships Pro]
<?php
/**
* Remove subscription delay for existing/past members.
* Add code to your site following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
* Please note that you should probably have the Initial Payment amount set if removing the Subscription Delay to avoid free periods.
* Take note of this gist to adjust the Level Cost Text dynamically - https://gist.github.com/kimcoleman/8d0e655be9d2e8fd9545da4692c8b786
*
* This code snippet is for advanced users/developers.
*
*/
//check at checkout if the user has used the trial level already
function my_pmpro_registration_checks() {
if ( is_admin() || ! is_user_logged_in() ) {
return;
}
$order = new MemberOrder();
$lastorder = $order->getLastMemberOrder( NULL, array( "success", "cancelled" ));
// If user currently has a membership level or previously had a membership level, remove custom trial.
if ( pmpro_hasMembershipLevel() || !empty( $lastorder ) ) {
remove_filter('pmpro_profile_start_date', 'pmprosd_pmpro_profile_start_date', 10, 2);
remove_action('pmpro_after_checkout', 'pmprosd_pmpro_after_checkout');
remove_filter('pmpro_next_payment', 'pmprosd_pmpro_next_payment', 10, 3);
remove_filter('pmpro_level_cost_text', 'pmprosd_level_cost_text', 10, 2);
remove_action('pmpro_save_discount_code_level', 'pmprosd_pmpro_save_discount_code_level', 10, 2);
}
}
add_filter( "init", "my_pmpro_registration_checks" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment