Skip to content

Instantly share code, notes, and snippets.

@JarrydLong
Last active August 11, 2023 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JarrydLong/c5b8be70ec793e2bb174da21dd95bf35 to your computer and use it in GitHub Desktop.
Save JarrydLong/c5b8be70ec793e2bb174da21dd95bf35 to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe gets the payment plan associated with the level that is purchased
* and shows the relevant payment plan on the Membership Account page.
*
* This is used as a workaround when using the Payment Plans Add On only.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function mypmpro_levels_for_user_with_plans( $levels, $user_id ) {
global $pmpro_pages;
//Only check for this on the Membership Account page
if( is_page( $pmpro_pages['account'] ) || is_page( $pmpro_pages['billing'] ) ) {
$order = new MemberOrder();
$order->getLastMemberOrder();
foreach( $levels as $level ) {
if( $order->membership_id == $level->ID ) {
//Lets see if this level was a plan
$plan = get_pmpro_membership_order_meta( intval( $order->id ), 'payment_plan', true );
if( ! empty( $plan ) ) {
$level->name = $plan->name;
$level->description = $plan->description;
$level->confirmation = $plan->confirmation;
$level->initial_payment = $plan->initial_payment;
$level->billing_amount = $plan->billing_amount;
$level->cycle_number = $plan->cycle_number;
$level->cycle_period = $plan->cycle_period;
$level->billing_limit = $plan->billing_limit;
$level->trial_amount = $plan->trial_amount;
$level->trial_limit = $plan->trial_limit;
$level->expiration_number = $plan->expiration_number;
$level->expiration_period = $plan->expiration_period;
}
}
}
}
return $levels;
}
add_filter( 'pmpro_get_membership_levels_for_user', 'mypmpro_levels_for_user_with_plans', 99, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment