Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active November 17, 2020 14:04
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 andrewlimaza/1f7c9414925b627cc4ac6f6e500d652b to your computer and use it in GitHub Desktop.
Save andrewlimaza/1f7c9414925b627cc4ac6f6e500d652b to your computer and use it in GitHub Desktop.
Require an Addon Package to be purchased for certain membership levels. [Paid Memberships Pro]
<?php
/**
* This code recipe requires an Addon Package to be purchased for a particular level. Please adjust the level ID on line 18.
*
* 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/
*/
function my_pmpro_require_ap_for_checkout( $continue ) {
global $pmpro_level;
// If things aren't okay, just bail.
if ( ! $continue ) {
return $continue;
}
if ( ! isset( $_REQUEST['ap'] ) && intval( $pmpro_level->id ) == 1 ) {
global $pmpro_msg, $pmpro_msgt;
$pmpro_msg = __( "Warning: This level requires an Addon Package to be purchased.", 'paid-memberships-pro' );
$pmpro_msgt = "pmpro_error";
$continue = false;
}
return $continue;
}
add_filter( 'pmpro_registration_checks', 'my_pmpro_require_ap_for_checkout', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment