Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active June 18, 2024 06:44
Show Gist options
  • Save andrewlimaza/47c18f00f9db38b6907053b1b3246dad to your computer and use it in GitHub Desktop.
Save andrewlimaza/47c18f00f9db38b6907053b1b3246dad to your computer and use it in GitHub Desktop.
Remove Subscription Delay for members and past members and set the initial price to the billing amount.
<?php
/**
* Remove the Subscription Delay for members and past members.
* This will change the price of the initial amount to the billing amount for past members.
* Tweak this code accordingly to your needs or hire a developer.
*
* To add this code to your site, please follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_one_time_sub_delay( $checkout_level ) {
// Logged-out users should always get the trial.
if ( ! is_user_logged_in() ) {
return $checkout_level;
}
$order = new MemberOrder();
$lastorder = $order->getLastMemberOrder( null, array( 'success', 'cancelled' ) );
$has_delay = get_option( 'pmpro_subscription_delay_' . $checkout_level->id, '' );
// If user currently has a membership level or previously had a membership level, remove sub delay.
if ( ( pmpro_hasMembershipLevel() || ! empty( $lastorder ) ) && ! empty( $has_delay ) ) {
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 );
// Set the initial amount now
if ( $checkout_level->billing_amount > 0 ) {
$checkout_level->initial_payment = $checkout_level->billing_amount;
}
}
return $checkout_level;
}
add_filter( 'pmpro_checkout_level', 'my_pmpro_one_time_sub_delay' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment