Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Load custom cancellation page for certain membership levels
<?php
/**
* Filter handler for `pmpro_pages_shortcode_cancel` (load custom cancellation page for certain membeship levels)
*
* @param string $content
*
* @return string
*/
function gc_custom_cancel_page( $content ) {
$standard_cancellation_ids = array( 5, ); // Petrolhead level ID
$custom_cancellation_page = 1027; // Using the 'Collectors Cancellation' page ID as the custom page
if ( isset( $_REQUEST['levelstocancel'] ) && $_REQUEST['levelstocancel'] !== 'all' ) {
//convert spaces back to +
$_REQUEST['levelstocancel'] = str_replace( array( ' ', '%20' ), '+', $_REQUEST['levelstocancel'] );
//get the ids
$old_level_ids = array_map( 'intval',
explode( "+",
preg_replace( "/[^0-9al\+]/", "", $_REQUEST['levelstocancel'] )
)
);
} else if ( isset( $_REQUEST['levelstocancel'] ) && $_REQUEST['levelstocancel'] == 'all' ) {
$all_levels = pmpro_getAllLevels( true, true );
$old_level_ids = array_keys( $all_levels );
} else {
$old_level_ids = false;
}
if ( false === $old_level_ids ) {
return $content;
}
// Iterate through the levels to cancel and load the custom page if applicable
foreach( $old_level_ids as $old_level_id ) {
// Do we load the custom cancellation page template?
if ( ! in_array( $old_level_id, $standard_cancellation_ids ) ) {
// Load the 'Collectors Cancellation' custom page (Page/Post ID: 1027)
$cancellation_page = get_post( $custom_cancellation_page );
$content = apply_filters( 'the_content', $cancellation_page->post_content );
break; // Exit the loop
}
}
return $content;
}
add_filter( 'pmpro_pages_shortcode_cancel', 'gc_custom_cancel_page', 20, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.