Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dparker1005/bc67b0a756cb2d8c042134e5ed9b5f50 to your computer and use it in GitHub Desktop.

Select an option

Save dparker1005/bc67b0a756cb2d8c042134e5ed9b5f50 to your computer and use it in GitHub Desktop.
Redirect away from the checkout page if a specific parameter is not in the URL
<?php
// Copy from below here...
/*
* Redirect away from the checkout page if a specific parameter is not in the URL
*/
function my_pmpro_require_url_param_for_checkout()
{
$request_key = 'checkout_password';
$request_value = 'my_password';
// With defaults set above, a sample checkout URL that would be allowed at checkout is
// www.yoursite.com/membership-account/membership-checkout/?level=1&checkout_password=my_password
global $pmpro_pages;
if( empty( $pmpro_pages ) )
return;
if ( is_page( $pmpro_pages['checkout'] ) && ( empty( $_REQUEST[ $request_key ] ) || $_REQUEST[ $request_key ] !== $request_value ) ) {
wp_redirect( site_url( 'page-explaining-you-need-level-1-first' ) ); //change url here
exit;
}
}
add_action('template_redirect', 'my_pmpro_require_url_param_for_checkout');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment