Last active
November 17, 2020 14:04
-
-
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]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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