Multiple levels; either set to only one at a time or prioritize rule sets?

Hi,

Right now on my site it’s necessary that users default to a ‘free subscription’ subscription. This works just fine. When they upgrade, however, they’re left with two subscriptions (and two levels because of it). This is also just fine so long as all if the rules set by the second, ‘premium subscription’ subscription are followed. This isn’t the case however in one particular case:

I have a tag called ‘premium’ that is set to visible by default. This can’t change. However, the free user level (under the free subscription) sets the tag as a negative rule so that it’s hidden. The premium level (under the premium subscription) sets it as a positive rule. When a user has both levels, it’s set to negative, and premium users cannot see [premium] wrapped content as they should be able to.

Again I realize a simple fix seems defaulting the tag to hidden, but it isn’t an option for a number of reasons, I’ve put the thought in there.

So where I’m left as I see it is with two options: either allow one level to override the rules set by the other (premium should override free), or automatically remove any other existing subscriptions when a new one is added.

I’d appreciate your input on this!

Cheers, and thanks for your time.

  • Barry
    • DEV MAN’s Mascot

    How’s your coding? You could put together a quick plugin that removes the user from one subscription when they are signed up for another.

    If you’re comfortable putting together some PHP then let me know and I’ll stick up the details on how to do it – you’ll need to know the ID’s of your subscriptions in order to be able to do it.

  • jetcooper
    • Flash Drive

    I’d have no problem writing that – already have 1200-some odd lines of code in a Membership plugin :wink:

    Some details would be fantastic – which hooks to use in order to cover all the bases and some pseudocode perhaps? Thanks for the help!

  • Barry
    • DEV MAN’s Mascot

    Ok, cool – right if you hook into membership_add_subscription you can then do some checks and remove the old subscription – the hook is defined as so:

    do_action( 'membership_add_subscription', $tosub_id, $tolevel_id, $to_order, $user_id);

    So the parameters we’re interested in really are $tosub_id which is the id of the subscription that the user has just been added to and $user_id which is the users identification.

    The code, assuming that we want to remove the user from subscription id 1 (the free one) when they sign up to subscription id 4 – note I’m typing this directly into this reply box, so it hasn’t been checked for syntax or functionality :slight_smile:.

    add_action('membership_add_subscription', 'cust_drop_a_sub', 10, 4);

    function cust_drop_a_sub($tosub_id, $tolevel_id, $to_order, $user_id) {

    if($tosub_id == 4 && current_user_on_subscription( 1 ) ) {
    // yep this is the one we want to drop.
    $member = current_member();
    if($member) {
    $member->drop_subscription( 1 );
    }

    }

    }

  • jetcooper
    • Flash Drive

    Great, thanks Barry! I won’t be able to test this out until later, but it seems very logical to me based on the other code I’ve written for Membership. It will be helpful in speeding up the process, definitely.

    I’ll let you know for sure when I get in there and try it out. Thanks again or your time thus far!

  • jetcooper
    • Flash Drive

    Hey Barry,

    Got it! Took a little bit of adjustment, but it was certainly close for having been written in the reply box!

    The only real flaw was using current_user() – when PayPal hits the page, there isn’t a current user, the session is elsewhere. So, using new M_Membership( $user_id ) gets around that.

    Other than that, I made some tweaks to reflect my subscription scenario – my free subscription is id #2, and there are 10+ other subscriptions, I need free to be cancelled no matter which they’re switching to. So the end result is this:

    add_action('membership_add_subscription', 'cust_drop_a_sub', 10, 4);

    function cust_drop_a_sub($tosub_id, $tolevel_id, $to_order, $user_id) {
    if($tosub_id != 2 ) {
    // yep this is the one we want to drop.
    $member = new M_Membership( $user_id );
    if($member) {
    $member->drop_subscription( 2 );
    }
    }
    }

    Cheers, Barry!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.