Created
July 4, 2019 18:24
-
-
Save LMNTL/c8549aa27d259a21a2841560f4a2e1c5 to your computer and use it in GitHub Desktop.
If a member has a pending check order for a level, don't show that level on the Levels page
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
/** If a member has a pending check order for a level, don't show that level on the Levels page | |
* Compatible with the Advanced Shortcode Add On. | |
* Requires PMPro and Pay By Check to be installed and configured | |
*/ | |
function my_pmprobc_dont_show_pending_level( $level_array ){ | |
// get the last order for the current user | |
$last_order = new MemberOrder(); | |
$last_order->getLastMemberOrder(NULL, NULL); | |
// bail if there wasn't a last order | |
if( !isset( $last_order->membership_id ) ) | |
return $level_array; | |
// bail if the last order wasn't a check order or in "pending"/"review"/blank status | |
if( $last_order->gateway != "check" || !in_array( $last_order->status, array( "pending", "review", "" ) ) ) | |
return $level_array; | |
//if we've made it this far, let's add all the non-pending levels to a new array and return that | |
$new_levels = array(); | |
foreach($level_array as $key => $level) | |
{ | |
if($level->id != $last_order->membership_id) | |
{ | |
$new_levels[$key] = $level; | |
} | |
} | |
return $new_levels; | |
} | |
add_filter( 'pmpro_levels_array', 'my_pmprobc_dont_show_pending_level'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment