Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active October 16, 2023 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/c9fb4f9bece3814ffa5120c23a61b811 to your computer and use it in GitHub Desktop.
Save ipokkel/c9fb4f9bece3814ffa5120c23a61b811 to your computer and use it in GitHub Desktop.
Redirect members to a custom confirmation page per level after PMPro checkout using the post ID #pmpro #confirmation #redirect
<?php
/**
* This recipe redirects members to a custom confirmation page per level after successful checkut using the post ID.
*
* You may create a custom page for each level and set the relation of these custom pages
* in the $confirmation_pages array.
* To obtain a page's post ID you may navigate to Pages > All Pages and hover over a page's name
* to have your browser display the edit post link. The URL parameter `post` reveals the page's post ID.
* You can also edit the page and can get the post ID on the address bar.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
add_filter( 'pmpro_confirmation_url', 'my_pmpro_confirmation_url_per_post_id', 10, 3 );
function my_pmpro_confirmation_url_per_post_id( $rurl, $user_id, $pmpro_level ) {
//change this use your membership level ids and page ids
$confirmation_pages = array(
1 => 14, // level ID 1 to post ID 14
2 => 15, // level ID 2 to post ID 15
);
foreach ( $confirmation_pages as $clevel => $cpage ) {
if ( pmpro_hasMembershipLevel( $clevel ) ) {
$rurl = get_permalink( $cpage );
}
}
return $rurl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment