Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/9013ad37078f5de8e6dfed618dc7a361 to your computer and use it in GitHub Desktop.
Save ipokkel/9013ad37078f5de8e6dfed618dc7a361 to your computer and use it in GitHub Desktop.
An example of how to use `pmpro_checkout_level` to redirect and interject communication with users during checkout. Sample taken from an attempt to prevent downgrading.
<?php // Do not copy
/**
* pmpro_checkout_level Use `pmpro_checkout_level` to redirect and interject communication with users during checkout.
*
* @param array $levels The array created in admin
*
* @return array Output of the array
*/
function pmpro_redirect_during_checkout( $level ) {
$current_level = $level->id;
if ( is_string( $current_level ) )
{
$current_level = intval($current_level);
}
// Check to see if the current user is downgrading (Gold to Silver or Gold to Free)
if ( pmpro_hasMembershipLevel( 3 ) && ( 1 === $current_level || 2 === $current_level ) ) {
// Re-direct them to levels page
wp_redirect( home_url( '/membership-levels' ) );
exit;
} // Check to see if the current user is downgrading (Silver to Free)
else if ( pmpro_hasMembershipLevel( 2 ) && 1 === $current_level ) {
// Re-direct them to page explaining why they cannot downgrade
wp_redirect( home_url( '/silver-downgrade-message' ) );
exit;
}
return $level;
}
add_filter( 'pmpro_checkout_level', 'pmpro_redirect_during_checkout' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment