Limiting Event Tickets by Membership - cStreet Campaigns

Limiting Event Tickets by Membership

NationBuilder users looking to boost membership sales have a new tool available to them in the form of event tickets. At cStreet Campaigns we've developed a method to limit event ticket access to people with specific active memberships. This could mean discounted tickets for members or VIP access for specific membership types, for example.

Our approach has three steps to it and requires some theme customization as well as a specific page setup.

Let’s start with the page setup.

When creating an event page and adding tickets in NationBuilder, your options are limited. However, our Creative Director and master NationBuilder hacker Amy Stuart, came up with a really clever solution.

When creating your ticket simply append |members:<membership name> to the end of it. This dictates which membership level will be able to purchase this particular ticket. We'll see how it's used in a bit.

Ticket Settings

Now we just have to write the Liquid code to parse this information and apply it. The first step of the theme customization is to know what active membership(s) a person has. Thanks to NationBuilder’s new Liquid membership variables you have access to all of a person’s active memberships. Previously, this only returned a person’s oldest membership, which was less useful. To account for folks having multiple active memberships, we’ve built a Liquid loop that creates an array of sorts.

{% assign memberships = '' %}
{% for membership in current_signup.memberships %}
    {% assign memberships = memberships | concat: membership.membership_type_name | concat: ", " %}
{% endfor %}
{% assign memberships = memberships | downcase %}

Now we have the variable memberships which contains a comma separated list of the person’s current active memberships. I recommend putting this in a partial (something like _membership_array.html) so you can include it in other pages without repeating any code.

The next step is in the event page templates, probably both regular and wide. You need a for loop that goes through each ticket level in page.event.ticket_levels and determines a few things:

  1. Whether that ticket is limited to members only.
  2. What membership level is needed to access it.
  3. Whether or not the person has that membership level.

Let’s walk through this code together. I’ve added comments (the stuff between <!-- and -->) to the code, to help describe what's happening.

<!-- Include the membership array partial -->
{% include 'membership_array' %}

<!-- iterate through each ticket level -->
{% for ticket_level in page.event.ticket_levels %}

  <!-- this sets the default for membersonly to false -->
  {% assign membersonly = false %}

  <!-- now we check whether the ticket level name contains "|members:" and if it does we set membersonly to true -->
  {% if ticket_level.name contains "|members:" %}
    {% assign membersonly = true %}
  {% endif %}

  <!-- This variable determines whether the person has the right membership to access this ticket level. -->
  <!-- The default is false. -->
  {% assign has_ticket_discount = false %}

  <!-- This is where the actual ticket fields are generated, depending on several variables. -->
  {% if request.logged_in? and request.current_signup.is_member? %}
    
    <!-- This captures the name of the membership the ticket is available to. -->
    {% if ticket_level.name contains "|members:" %}
      {% capture ticket_level_member_access %}
        {{ ticket_level.name | split: "|members:" | last | downcase }}
      {% endcapture %}
      
      <!-- This determines whether the person has the membership required to access that ticket. -->
      {% if memberships contains ticket_level_member_access %}
        {% assign has_ticket_discount = true %}
      {% endif %}
    {% endif %}
  {% endif %}

  <!-- And this is where you start creating the ticket purchase form. -->
  <div class="card ticket-card">
    <div class="row">
      <div class="col-xs-8">
        <!-- This removes the "|members:" stuff from the ticket name so you can display just the cleaned up name. -->
        {% if ticket_level.name contains "|members:" %}
          {{ ticket_level.name | split: "|members:" | last }}
        {% endif %}

        <!-- If the ticket has no limit, or is not sold out, it displays the ticket name. -->
        {% if ticket_level.quantity_remaining == nil or ticket_level.quantity_remaining > 0 %}
          <h5>{{ ticket_level.name | split:"|" | first}}</h5>
          <strong class="brightblue">{{ticket_level.amount}}</strong>

          {% if ticket_level.description.size > 0 %}
            <hr/>
            <div class="description">{{ ticket_level.description }}</div>
          {% endif %}
        <!-- If the ticket is sold out, it displays that message. -->
        {% else %}
           <div class="notice warning">Sorry, this ticket is sold out</div>
        {% endif %}

      </div>
      <div class="col-xs-4">
         
        <!-- Here is where the membership access comes into play. -->
        {% if membersonly %}
          {% if has_ticket_discount %}
            <!-- If the ticket is available to members only, and the person has the appropriate membership, it displays the normal ticket purchase form. -->
            {{ ticket_level.form_quantity | replace:'class="quantity"','class="quantity form-control"' | split:">" | first }}>
          {% else %}
              
            {% if request.logged_in? %}
              <!-- If the person is logged in but does NOT have the required membership, they are asked to "Get this membership" or "Become a member". -->
              {% if request.current_user.is_member? %}
                <a class="tag" href="/become_a_member">Get this membership</a>
              {% else %}
                <a class="tag" href="/become_a_member">Become a member</a>
              {% endif %}
            {% else %}
              <!-- If they are logged out, they're asked to log in. -->
              <a class="tag" href="{{page.full_url}}?adminlogin">Log in to access</a>
            {% endif %}
          {% endif %}
        {% else %}
          <!-- If the ticket does not require a membership to purchase, they get the normal ticket form. -->
          {{ ticket_level.form_quantity | replace:'class="quantity"','class="quantity form-control"' | split:">" | first }}>
        {% endif %}
      </div>
    </div>
  </div>
{% endfor %}

So there you have it, you can now limit event tickets by membership type, like we did on this client's website.

Event tickets limited by membership

I’d love to hear what you’re doing with NationBuilder’s new membership liquid variables. Leave your comments below!

originally published Monday, February 26, 2018