Support

Home Forums Event Espresso Premium Hiding Ticket for logged in users who don't have capability

Hiding Ticket for logged in users who don't have capability

Posted: May 1, 2023 at 3:55 pm

Viewing 11 reply threads


sogtalks@gmail.com

May 1, 2023 at 3:55 pm

Hello,
I have an event with four tickets, one of which is available by capability only ‘rsvp’.

Logged out users can see:

  • all tickets but must login to purchase/claim ticket
  • Ticket with capability – logged out users see “Must login to see this ticket option” (it’s a free ticket)

Logged in users can see:

  • all tickets but must login to purchase/claim ticket
  • Ticket with capability – I am trying to hide this from users/members who either don’t have this capability (all but one) or don’t have the correct membership level

I am using PMP for members
Cap is ‘rsvp’
Cap member is ‘pmpro_role_12’
The site: https://tinyurl.com/4ac4f97z
Also the ticket with the cap isn’t being restricted – I can supply a login to test

I have tried a variety of actions but in every instance the tickets still displays when it shouldn’t (ie non-cap user or not correct membership level

Example – membership role with cap

add_filter( 'FHEE__EED_WP_Users_Ticket_Selector__maybe_restrict_ticket_option_by_cap__no_access_msg_html', 'event_ticket_hider' );

function event_ticket_hider( $no_access_msg_html ) {
	if ( ! is_user_logged_in() ) {
		return $no_access_msg_html;
	}

    if ( ! function_exists( 'pmpro_hasMembershipLevel' ) || pmpro_hasMembershipLevel( 'pmpro_role_12' ) ) {
        return '';
    }

}

Example – by cap

add_filter( 'FHEE__EED_WP_Users_Ticket_Selector__maybe_restrict_ticket_option_by_cap__no_access_msg_html', 'event_ticket_hider' );

function event_ticket_hider( $no_access_msg_html ) {
	if ( ! is_user_logged_in() ) {
		return $no_access_msg_html;
	}

    if ( ! current_user_can( 'rsvp' ) ) {
        return '';
    }
    
}

Thank you


sogtalks@gmail.com

May 1, 2023 at 4:52 pm

This reply has been marked as private.


Garth

  • Support Staff

May 3, 2023 at 1:10 pm

You’ll need to have the WordPress User Integration installed and active to set the role or capability for the ticket, there will be an additional settings area to select the role or add a custom capability in the advanced settings of the ticket. Be sure to be using version 2.1.1.p or greater of the WP User Integration. This is what it looks like in EE5: https://www.screencast.com/t/jRe9G7af


sogtalks@gmail.com

May 3, 2023 at 2:05 pm

Garth,

I have EE Version 5.0.3.p installed with WP User Integration 2.2.1.

I believe I have the ticket setup properly but can’t hide it from non-cap logged users.

I will send you admin login.

Thank you


sogtalks@gmail.com

May 3, 2023 at 2:08 pm

This reply has been marked as private.


Garth

  • Support Staff

May 3, 2023 at 4:11 pm

Can you send a link to your website, the tiny url above is not working.


sogtalks@gmail.com

May 3, 2023 at 4:15 pm

This reply has been marked as private.


Garth

  • Support Staff

May 3, 2023 at 4:24 pm

I enabled the New Editor in Event Espresso > Events > Default Settings

If you edit a ticket, you will now see those settings. Here is a video: https://www.screencast.com/t/B4oO1t5RTGt4


sogtalks@gmail.com

May 3, 2023 at 5:15 pm

Garth,

I am a little confused. I had the capability set before and that hasn’t changed with the new editor.

I used a couple of different variations of code(above) to try and hide the ‘rsvp’ capable ticket from those users who don’t have that capability when logged in. You can use the resident@… user I included above.

The situation is that I can’t hide the ticket and also anyone claim that ticket, without ‘rsvp’ capability.

Thank you.


Tony

  • Support Staff

May 4, 2023 at 8:07 am

I used a couple of different variations of code(above) to try and hide the ‘rsvp’ capable ticket from those users who don’t have that capability when logged in. You can use the resident@… user I included above.

The resident user you added above is assigned to a role (pmpro_role_9) which has the rsvp capability, so it’s expected for that account to have access.

The situation is that I can’t hide the ticket and also anyone claim that ticket, without ‘rsvp’ capability.

When not logged in, I see the ‘no access’ messages meaning I don’t have the capability:

https://monosnap.com/file/UAh5rFfUnwGmUiXNb0leWmFjlAVW71

So you basically just want to remove the ticket from view from users who are logged in but still don’t have the correct capability?

Logged-in users who do NOT have the cap would see the same screen as my screenshot above, so you just want to remove that row from view?


sogtalks@gmail.com

May 4, 2023 at 9:45 am

That is correct.

I am so sorry for wasting your time. It works as expected with the correct role/settings. Too much going on at once.

I appreciate the fresh eyes. We love Event Espresso!

Thank you.


Tony

  • Support Staff

May 4, 2023 at 12:18 pm

So it sounds like you need something like this:

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

You may want to add a check to see if the current user is an admin and allow them to see the tickets, but the above gets you the functionality you are looking for.

Viewing 11 reply threads

The support post ‘Hiding Ticket for logged in users who don't have capability’ 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