[Pro Sites] CONDITIONALS: Available Pro Sites Levels/choices based on Membership 2 memberships

Hi - I plan on creating 3 new user roles (logged-out guest, logged-in free member, logged-in paid “verified” member), and then specify different Pro Site Levels/choices depending on the logged-in user’s user role. [Using Pro Sites (PS), Membership2 (M2) & User Role Editor (URE)]. Thus, I’m trying to do the following:

> new user role 1 (URE)
> logged-out guest w/ user role 1 specific capabilities (M2)
> cannot create/purchase a Pro Site (only for user roles 2 & 3)
//done. Pro Sites requires users to be logged-in//

> new user role 2 (URE)
> free logged-in member; user role 2 specific capabilities (M2)
? can only create new Pro Site from PS choices “level 1” or “level 2”, but not “level 3” or “level 4”

> new user role 3 (URE)
> paid logged-in member; user role 3 specific capabilities (M2)
? can only create new Pro Site from PS choices “level 3” or “level 4”, but not “level 1” or “level 2”

My issue is with the two "?" sections. Can this be done?

Thank you,

Sam

  • Nahid

    Hey Sam !
    Hope you are having a great day!

    Though this isn't possible out of the box with either of the plugins, this can be achieved by adding some bits of custom code. After the user roles have been set up, please try adding the following snippet of code in your primary site's theme's (more preferably, child theme's) functions.php file:

    add_action( 'wp_footer', 'prosite_level_conditions' );
    function prosite_level_conditions() {
    
    	global $psts;
    	if ( ! is_page() || get_the_ID() != $psts->get_setting( 'checkout_page' ) ) {
        	return;
    	}
    
    	$user = wp_get_current_user();
    	if ( in_array( 'new-user-role-1', (array) $user->roles ) ) {
    	// Change 'new-user-role-1' to your desired user role, who should have access to levels 1 & 2
    		?>
    		<script>
    			( function( $ ) {
    				$( document ).ready( function() {
    					$( '#prosites-checkout-table .psts-level-3' ).remove();
    					$( '#prosites-checkout-table .psts-level-4' ).remove();
    				} );
    			} ( jQuery ) );
    		</script>
    		<?php
    	} elseif ( in_array( 'new-user-role-2', (array) $user->roles ) ) {
    	// Change 'new-user-role-2' to your desired user role, who should have access to levels 1 & 2
    		?>
    		<script>
    			( function( $ ) {
    				$( document ).ready( function() {
    					$( '#prosites-checkout-table .psts-level-1' ).remove();
    					$( '#prosites-checkout-table .psts-level-2' ).remove();
    				} );
    			} ( jQuery ) );
    		</script>
    		<?php
    	}
    }

    Alternatively, you can also add the code in a mu-plugin. That'll require you to paste the mentioned code in a PHP file that ends with the extension .php, e.g. "anyname.php". The mentioned code should have a "<?php" definition at the start of the file. This PHP file should be placed in {your root WordPress folder}/wp-content/mu-plugins (you'll need to create the folder named "mu-plugins" if it is not there already).

    Explanation: The above code checks the user role of the logged in user and based on the applied conditions, it displays the Pro Sites Levels in the Pro Sites Checkout page. Within the above code snippet, you'll need to define your user role name in line #11 for the user role who should be able to signup for Pro Sites levels 1 and 2 only and in line #23 or the user role who should be able to signup for Pro Sites levels 3 and 24 only. I've added comments within the code to your convenience.

    Hope this helps. Let us know if this works for you. Thanks!

    Kind regards,
    Nahid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.