Support

Home Forums WP User Integration Custom pricing for Restrict Contet Pro

Custom pricing for Restrict Contet Pro

Posted: April 13, 2023 at 10:30 pm


queensland young lawyers

April 13, 2023 at 10:30 pm

I am trying to create a ticket that is restricted to RCP members.

I think this is the same as this ticket.
https://eventespresso.com/topic/restricting-ticket-using-wp-user-capability-and-restrict-content-pro/

Can you please adivse how ot do this?


queensland young lawyers

April 13, 2023 at 11:33 pm

I’ve come up with this and it seems to work.
Can we hide the non-member tickets from members?

function qyl_custom_current_user_can( $allcaps, $caps, $args, $user ) {
    if ( in_array( 'member', $caps ) && function_exists( 'rcp_get_customer_by_user_id' ) ) {
        $customer = rcp_get_customer_by_user_id( $user->ID );
        if ( ! empty( $customer ) ) {
            $memberships = $customer->get_memberships();
            if ( ! empty( $memberships ) ) {
                $allcaps['member'] = true;
            }
        }
    }

    return $allcaps;
}


Tony

  • Support Staff

April 14, 2023 at 5:16 am

Hi there,

I’ve come up with this and it seems to work.

What is the above function hooking into?

Can we hide the non-member tickets from members?

Are non-members still logged in?

We have a snippet that can return nothing if a user does not have access to the ticket, so rather than showing the message about logging in, it removes the ticket completely.

Will that work for you?


queensland young lawyers

April 16, 2023 at 5:40 pm

Hi Tony,

forgot to add that line:
add_filter( 'user_has_cap', 'qyl_custom_current_user_can', 10, 4 );

Non-members will not be logged in, so we’d need them to still see the ticket, if there’s a snippet for that.


Tony

  • Support Staff

April 17, 2023 at 6:30 am

So to confirm, you want the ticket to be removed if both of these are true:

1. No capability is set on the ticket itself (meaning its available to all)
2. They are logged in

If so, this snippet should work for you:

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

Note the above snippet still shows all tickets when in the admin AND will show all tickets for administrators.

The support post ‘Custom pricing for Restrict Contet Pro’ 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