Would it be possible to hide some memberships randomly?

I’m working on some market research when launching a new offering and I would like to have the option to set up 4 memberships with the same content available but with a different price each one, and for this reason I would like the registration page to only show 1 membership at a time and to hide the rest from the registration page and everywhere on the site (like if there was only one membership active on the site).

To summarize, I’d like to have the option to only register for one of the 4 memberships (same content but different price) and to hide ALL the rest during the registration process (and after the registration as well).

Would it be possible to achieve this using M2P?

2. Can I have a $0 membership that expires? If I create an unpaid membership, but charge them outside the registration process, will that work?

  • Ash
    • WordPress Hacker

    Hello Jack Lavender

    To show a random membership on register page, please try the following code:

    <?php
    // Silence is golden.
    
    add_action( 'wp_head', function() {
    	?>
    	<style>
    		.ms-membership-form{display: none}
    	</style>
    	<script type="text/javascript">
    		jQuery(function($){
    			var len = $( '.ms-membership-form' ).length,
    				random = Math.floor( Math.random() * len ) + 1;
    				alert(random);
    			$( '.ms-membership-form:nth-child(' + random + ')' ).show();
    		});
    	</script>
    	<?php
    } );

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    2. Yes, you can, just set it finite membership.

    If I create an unpaid membership, but charge them outside the registration process, will that work?

    Yep, that would work too. But maybe you can use manual payment gateway as well.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

  • Jack Lavender
    • Site Builder, Child of Zeus

    I will give this a try. One follow-up question (I'm pretty sure I know the answer, but I'll ask anyway):

    Will this give me a random membership across ALL my available memberships?

    And when you answer "Yes", the obvious follow-up is "Can I restrict it to a random membership in a group of memberships"?

    My client sells course materials for K-8 grade students. The program has six characters. Historically, they've only sold all six characters together, but now they're starting to sell them individually. So, I'm starting with the first character (Ruby). I'd like to be able to create a group of membership options for her. Then, when we launch the next character (Philo), do the same. However, I don't want the people looking for Philo to get Ruby membership options. I hope that's clear.

    Thanks.

  • Ash
    • WordPress Hacker

    Hello Jack Lavender

    Will this give me a random membership across ALL my available memberships?

    Yes :slight_smile:

    And when you answer "Yes", the obvious follow-up is "Can I restrict it to a random membership in a group of memberships"?

    No :slight_frown:

    But you can just make a membership private, so it will never appear on the membership list. Is that something work for you?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.