Conditionals based on Membership Level

Good day folks,

So I have search through the documentation and the forum and cannot find anything that is leading me in the right direction. I did see there is some docs on this topic, but maybe it is me, but I cannot wrap my head around it.

So the question is, “How do I show content based on a membership level”?

I have Woocommerce installed with the Woocommerce Membership plugin. I have a few memberships and want to be able to show the content based on those memberships.

I know this is not correct, but this is the idea of what I am trying to achieve.

<div class="nsc-course__wrapper">
  <div class="nsc-course__inner">
    <Loop type="woo_user_membership">
      <If field="wc_memberships_is_user_active_member" is="full-course">
        <p class="nsc-course__fullCourse">
          This is the Full Course Content
        </p>
        <Else if wc_memberships_is_user_active_member is="basic" />
        <p class="nsc-course__basic">
          This is the Basic Course Content
        </p>
        <Else />
        <p class="nsc-course__guest">
          This is what a guest would see
        </p>
      </If>
    </Loop>
  </div>
</div>

Any help would be greatly appreciated. =)

Cheers

Hi Mike!
It looks like you’re using features from our beta pro plugin. Are you part of the beta? If not, you can sign up here. If you already have the pro plugin installed, I might approach creating the logic you need this way:

<div class="nsc-course__wrapper">
  <div class="nsc-course__inner">
    <Loop type="woo_user_membership" user=current>
      <Loop field=plan>
       <Set name="current_user_membership_{Field name /}"><If field=is_active>true<Else />false</Set>
      </Loop>
      <If variable="current_user_membership_full-course" value="true">
        <p class="nsc-course__fullCourse">
          This is the Full Course Content
        </p>
        <Else if  variable="current_user_membership_basic" value="true" />
        <p class="nsc-course__basic">
          This is the Basic Course Content
        </p>
        <Else />
        <p class="nsc-course__guest">
          This is what a guest would see
        </p>
      </If>
    </Loop>
  </div>
</div>

First, we use the user=current parameter (documented here) on the woo_user_membership loop to only get the current user’s memberships instead of every user membership on the site.

Then we take the example markup from the docs and use the plan field loop and is_active field to check which plan is active for the current user’s membership. We create a dynamically named variable for each plan in the loop to save us some time writing logic by passing the plan name to the variable name. Then outside of the plan loop, we test our variables to determine which content to display. I haven’t tested this, so let me know if it works for you! You could probably simplify this by using the plan_id and is_active fields directly inside the woo_user_membership loop, you’d just have to test against the plan IDs instead of the names:

<div class="nsc-course__wrapper">
  <div class="nsc-course__inner">
    <Loop type="woo_user_membership" user=current>
      <If field=is_active>
        <If field=plan_id value=123>
          <p class="nsc-course__fullCourse">
            This is the Full Course Content
          </p>
        <Else if field=plan_id value=234 />
          <p class="nsc-course__basic">
            This is the Basic Course Content
          </p>
        </If>
      <Else />
        <p class="nsc-course__guest">
          This is what a guest would see
        </p>
      </If>
    </Loop>
  </div>
</div>
1 Like

Hello Julia,

Thank you for the quick reply and the detailed response.

I have signed up for the beta, but sadly I am standing in line on the waiting list. =(

Let me have a go with the info you provided and see what I can come up with. =)

Cheers