Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/6ff1d5f45688784a9235e6238fb7dcc8 to your computer and use it in GitHub Desktop.
Save kimwhite/6ff1d5f45688784a9235e6238fb7dcc8 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
<?php // do not copy this line.
/**
* This recipe will send a user with no level straight to the LEVEL 1 checkout
*
* 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/
*/
/*
* Redirect away from the checkout page if a specific parameter is not in the URL
*/
function my_pmpro_require_url_param_for_checkout()
{
global $pmpro_pages;
if ( pmpro_hasMembershipLevel() ) {
return;
}
if( empty( $pmpro_pages ) )
return;
if ( is_page( $pmpro_pages['checkout'] ) && ( empty( $_REQUEST[ 'level' ] ) || $_REQUEST[ 'level' ] != '1' ) ) {
wp_redirect( site_url( '/membership-account/membership-checkout/?level=1' ) );
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