Forked from pbrocks/pmpro-redirect-during-checkout.php
Last active
July 5, 2019 11:47
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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