Support

Home Forums Event Espresso Premium Hiding Tickets for Certain Logged In User Roles

Hiding Tickets for Certain Logged In User Roles

Posted: March 28, 2023 at 7:29 am

Viewing 25 reply threads


Katelyn

March 28, 2023 at 7:29 am

Is there a way to hide certain tickets for certain capabilities that don’t have a set purchase limit?

IE: I have a Member role on our site and I want only Member roles to be able to purchase these tickets when they log into the website.

I’ve tried a previous code snippet and it didn’t work as expected.


Garth

  • Support Staff

March 28, 2023 at 8:59 am

Hi Katelyn,

The WP User Integration Add-on will help you with tickets for members of your website. Combined with the WordPress and Event Espresso capabilities system you can require that people are logged-in to your website before they can purchase tickets and restrict certain types of tickets to those who have the right custom capabilities/privileges.

With our WP user integration add-on, you’ll be able to setup member pricing and also offer public pricing. It works by integrating with a membership plugin like Paid memberships pro or another plugin.

Here is an example of how it works with S2member: http://ee-screenshots.s3.amazonaws.com/ee4/ee4-s2member-roles-tickets.jpeg

You set a capability for a pricing option and then a member that has access will be able to register for those pricing options.

Roles are just a bundled set of capabilities, so, if you choose a capability that is contained in a certain role, then you’re good to go.

Does that help?


Katelyn

March 28, 2023 at 9:27 am

I am using that, but I would like only those tickets to show when the user signs in. Rather than them see the two ticket options.


Garth

  • Support Staff

March 28, 2023 at 9:50 am

Choose a capability that is unique in a certain role and use that capability respectively for a certain ticket. Then those with just that certain capability will see the certain ticket.


Katelyn

March 28, 2023 at 9:50 am

I would like the member to see only the member ticket, none of the other tickets.


Garth

  • Support Staff

March 28, 2023 at 9:56 am

Can you send us a screenshot of how the ticket capabilities are set up and give us a link to the event?


Katelyn

March 28, 2023 at 10:00 am

This reply has been marked as private.


Garth

  • Support Staff

March 28, 2023 at 10:57 am

The regular priced “Zoom” ticket does not have any capability which means that ticket will be available to everyone always. There is no way to hide a ticket that is configured to be visible to the public. The only way to hide this ticket from members it to add a capability to this ticket. But if you add a capability to this ticket, then it needs to be a capability that is for non-members, which also means that people not logged in to your website will not be able to buy a ticket or register until they create an account as a non-member.

The “Zoom: Members” ticket does require a capability “membership_discount”.

Does that make sense?


Katelyn

March 28, 2023 at 10:59 am

Thanks. So, I would have to have custom development to achieve this then?


Tony

  • Support Staff

March 28, 2023 at 1:21 pm

Hi there,

Will it always be the case that logged in users will have access to to a ‘member’ ticket?

I have a snippet you can use to do what you are trying to do here:

https://gist.github.com/Pebblo/16a7dabb6a6d8f0f3d4370ccda06098b#file-functions2-php

You can add that to a custom functions plugin on your site, we have some documentation on creating one here:

https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/

What that does is remove any tickets with no capability set on them when you are logged in, unless your account has the ‘manage_options’ capability (an administrator) in which case you will always see all tickets.


Katelyn

March 29, 2023 at 7:05 am

Does it have to be input as a plugin or can I do it within a Code Snippet plugin? It’s not working, currently. Both tickets are still showing up for someone logged in with a Member Role.


Tony

  • Support Staff

March 30, 2023 at 6:56 am

Does it have to be input as a plugin or can I do it within a Code Snippet plugin?

It depends on what the code snippet plugin is doing, I’d recommend using a physical plugin to store custom functions, we have some documentation on creating one here:

https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/

I just tested that snippet within a plugin with an Admin, Subscriber and Regular visitor:

https://monosnap.com/file/QqVcBqm7jnGoJcmevYOrqLEKFThPob

(The capability set on the member ticket is just ‘read’)


Katelyn

March 30, 2023 at 6:57 am

This reply has been marked as private.


Tony

  • Support Staff

March 30, 2023 at 7:13 am

Okay; do I need to have a ticket cap?

Need a ticket capability?

How else are you limiting the ticket access to be member only?


Katelyn

March 30, 2023 at 7:16 am

Sorry; I mean this portion.

//Pull the current minimum capability set on the ticket.
$cap_required = $ticket->get_extra_meta( ‘ee_ticket_cap_required’, true );


Tony

  • Support Staff

March 30, 2023 at 7:25 am

What that’s doing is checked to see if the ticket has a capability set on it, its pulling in the capability set on the ticket with that line.

So its checking to see if something is set here:

https://monosnap.com/file/hYBdcW1ipxsIoaRzvAnZdu4Cf8DVZr

If so, that ticket is some kind of ‘member’ ticket, otherwise it’s a ‘normal’ ticket.


Katelyn

March 30, 2023 at 8:07 am

Okay, so, I did create a plugin for it and it’s still showing both tickets. Any assistance would be most helpful.

The capability should “membership_discount” and I cannot use “read” as there are two different types of user roles logging in.


Tony

  • Support Staff

March 30, 2023 at 8:57 am

Can you link me to the event please?


Katelyn

March 30, 2023 at 9:00 am

This reply has been marked as private.


Tony

  • Support Staff

March 30, 2023 at 9:05 am

Okay, so, I did create a plugin for it and it’s still showing both tickets. Any assistance would be most helpful.

Ok, so starting from the basics.

You made no changes to the plugin other than adding my snippet, right?

Has that custom functions plugin been activated on the site?

The capability should “membership_discount” and I cannot use “read” as there are two different types of user roles logging in.

I don’t want you to use read, it doesn’t matter what the capability is set to, the snippet just checks to see if something is set in that capability field, it there is it’s a ‘member ticket’.

Then is checks to see if you are logged in, and NOT an administrator.

Then, shows you only the tickets that have a capability set on them and removed the ticket without any.


Katelyn

March 30, 2023 at 9:12 am

The only thing I changed in the plugin was the manage_options portion. Was I not to change that portion?

//Check for a capability set and if the user is logged in but not an administrator.
if( empty( $cap_required ) && ( is_user_logged_in() && ! current_user_can( ‘manage_options’) ) ) {
return ”;
}


Tony

  • Support Staff

March 30, 2023 at 9:22 am

No, use the code as is, you don’t need to change the code I gave you at all.

//Pull the current minimum capability set on the ticket.
$cap_required = $ticket->get_extra_meta( ‘ee_ticket_cap_required’, true );

That link pulls the current ticket capability to see if it’s a member ticket.

if( 
    //First confirm if the ticket DOES NOT have a capability set on it.
    empty( $cap_required ) 
    // Now check if the user is logged in and NOT an admin
    && ( is_user_logged_in() && ! current_user_can( ‘manage_options’) ) 
) {
    // If the ticket DOES NOT have a capability,
    // the user is logged in but NOT an admin
    // remove the ticket from display.
    return ”;
}

That’s what that code is doing.


Katelyn

March 30, 2023 at 9:31 am

Okay, that worked. But those who are logged in and do not have the capability, it is not showing ANY tickets even the regular tickets.


Tony

  • Support Staff

March 30, 2023 at 9:41 am

That’s why I asked the above question in my first reply here:

https://eventespresso.com/topic/hiding-tickets-for-certain-logged-in-user-roles/#post-340882

Will it always be the case that logged in users will have access to to a ‘member’ ticket?

If that’s not the case (and it sounds like it’s not) then you can’t use that snippet.


Katelyn

March 30, 2023 at 9:43 am

Okay, I apologize for missing that. So there’s nothing that would work for this use case then?


Tony

  • Support Staff

March 31, 2023 at 7:17 am

I’ve been trying to think of a way around this.

The problem is that with the way it works now your requirements conflict with each other.

If the user is logged in you don’t want to show them the ‘public’ tickets

UNLESS

The user is logged in and doesn’t have access to any of the ‘member’ tickets.

But the check on the tickets is based on each individual ticket row so each row isn’t aware of the previous/next one to know if you should display the member ticket or public ticket.

How do you determine the different between just a standard logged in user and what we would consider a ‘memeber’ (someone who has access to the tickets currently) on the site?

Viewing 25 reply threads

The support post ‘Hiding Tickets for Certain Logged In User Roles’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso