Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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