Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ideadude/bc2de3c2071ae58e64310b27aef902e1 to your computer and use it in GitHub Desktop.
Save ideadude/bc2de3c2071ae58e64310b27aef902e1 to your computer and use it in GitHub Desktop.
Tell PMPro and PMPro Add On Packages to use the user's current level or the most expensive level when checking out for an add on package.
/**
* Use new pmproap_text_level_id filter to choose the user's currenet level OR the most expensive level with access.
* The level with the highest initial payment is chosen.
* Update this code as needed and add to a custom plugin.
*/
function choose_most_expensive_level_for_addon_packages( $text_level_id, $post_id, $user_id, $post_levels ) {
if ( ! pmpro_hasMembershipLevel( $text_level_id, $user_id ) ) {
$highest_initial_payment = 0;
foreach ( $post_levels as $level_id ) {
$level = pmpro_getLevel( $level_id );
if ( $level->initial_payment > $highest_initial_payment ) {
$highest_initial_payment = $level->initial_payment;
$text_level_id = $level_id;
}
}
}
return $text_level_id;
}
add_filter( 'pmproap_text_level_id', 'choose_most_expensive_level_for_addon_packages', 10, 4 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Set a Specific Checkout Level When Using Addon Packages" at Paid Memberships Pro here: https://www.paidmembershipspro.com/set-a-specific-checkout-level-when-using-addon-packages/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment