Support

Home Forums Event Espresso Premium Display only the ticket type that matches the user role for ticket selector

Display only the ticket type that matches the user role for ticket selector

Posted: March 6, 2017 at 12:23 pm


jubileequeen

March 6, 2017 at 12:23 pm

Hello.

I have 3 different prices for clients. Non logged in clients (subscriber), dealsite offer #1 price (role:S2MEMBER LEVEL 1), dealsite offer #2 pricing (role:S2MEMBER LEVEL 2). I don’t want S2MEMBER LEVEL 1 AND LEVEL2 seeing any other pricing than the single ticket set to match their role and to exclude dealsite1 and dealsite pricing from non-logged in clients (role:subscriber).

Below is the price structure and tickets to display.
NON-LOGGED IN: $72
S2MEMBER LEVEL 1(DEALSITE1): $39
S2MBMER LEVEL 2 (DEALSITE2): $42


Tony

  • Support Staff

March 7, 2017 at 3:07 am

Hi there,

You can use a function like this:

https://gist.github.com/Pebblo/106393acd850cb83c3798c66a9c5a19a

Add that to a Custom Functions Plugin on your site and if a user does not have the capability assigned to their account that is set on the ticket then the ticket will not show.

I don’t want S2MEMBER LEVEL 1 AND LEVEL2 seeing any other pricing than the single ticket set to match their role and to exclude dealsite1 and dealsite pricing from non-logged in clients (role:subscriber).

The capability set on a ticket is the minimum capability required to access the ticket, one thing to remember is S2 ‘Stacks’ capabilities, for example a level 2 role has most of the capabilities the level 1 member has meaning they would see both.

You will need to use a unique capability from each level on each of the ticket to do what you need.


jubileequeen

March 13, 2017 at 4:29 pm

Thanks for the response. I have put that to use.

Now, how can I display only a specific ticket type such as Dealsite ticket only for each event. It does not matter if I use the ticket selector to do this or not.

I just need to show the Event Title, Date, Ticket Name, Ticket Price, Event Description.


Tony

  • Support Staff

March 14, 2017 at 3:30 am

I’m not sure I understand, can you provide an example?


jubileequeen

March 14, 2017 at 9:35 am

In example, I need to distinguish and separately display 3 pricing models for tickets for a single event using Event Espresso.

Event A – Travel Tour
Adult Ticket $54 (non member)
Child Ticket $29 (non member)
Dealsite General Ticket $33 (member dealsite 1)
Dealsite General Ticket $35 (member dealsite 2)

For Dealsite 1 display only:
Event A – Travel Tour
Aug 8, 2017 1pm – 2pm
Dealsite General Ticket $33

For Dealsite 2 display only:
Event A – Travel Tour
Aug 8, 2017 1pm – 2pm
Dealsite General Ticket $35

For Standard non-member display only:
Event A – Travel Tour
Aug 8, 2017 1pm – 2pm
Adult Ticket $54
Child Ticket $29

Viewing as Administrator:
Event A – Travel Tour
Aug 8, 2017 1pm – 2pm
Adult Ticket $54
Child Ticket $29
Dealsite General Ticket $33
Dealsite General Ticket $35


jubileequeen

March 14, 2017 at 9:40 am

Also, I am looking for a way to blank out the email address for a registered user so they always have to type it. I am using a dealsite user for all dealsite 1 registrations pricing model 1 and dealsite 2 for all dealsite pricing model 2, pricing model 3 is non-registered.


Tony

  • Support Staff

March 17, 2017 at 6:55 am

To remove the tickets that don’t have caps set to them for logged in users you can use this function:

https://gist.github.com/Pebblo/16a7dabb6a6d8f0f3d4370ccda06098b

To remove the tickets that user don’t actually have access to you can use this function:

https://gist.github.com/Pebblo/106393acd850cb83c3798c66a9c5a19a

For the email question take a look at how the filter_answer_for_wpuser method within the WP User Integration add-on returns the values, you’ll want to hook in using the same hook, check for the email question field and return nothing for that field.

However based on the above each time a user updates the details on the registration form it will update the details on the user account when using the add-on, there is an option to disable that but then those registrations made with the details that don’t match the account details will not show up in the My Events Section.


jubileequeen

March 22, 2017 at 4:59 am

Hello. I tried this on my local test and it (https://gist.github.com/Pebblo/16a7dabb6a6d8f0f3d4370ccda06098b)did not work for me when I inserted in the functions.php.


jubileequeen

March 22, 2017 at 5:04 am

Here is the code that I tried inserting into EE_WP_Users_Ticket_Selector.module.

It did the job of hiding the code when user “groupon” was used. However, for some reason I cannot get my payment gateway to return back a response after the correct amount (72.95 plus taxes) shows in the payment gateway. The customer is getting charged but the customer returns to the registration checkout page being blank.

//****************** code start ******************
<?php
if ( ! defined(‘EVENT_ESPRESSO_VERSION’)) exit(‘No direct script access allowed’);
/**
* This file contains the module for the EE WP Users addon ticket selector integration
*
* @since 1.0.0
* @package EE WP Users
* @subpackage modules
*/
/**
*
* EED_WP_Users_Ticket_Selector module. Takes care of WP Users integration with ticket selector.
*
* @since 1.0.0
*
* @package EE WP Users
* @subpackage modules
* @author Darren Ethier
*
* ————————————————————————
*/
class EED_WP_Users_Ticket_Selector extends EED_Module {

public static function set_hooks() {
add_filter( ‘FHEE__ticket_selector_chart_template__do_ticket_inside_row’, array( ‘EED_WP_Users_Ticket_Selector’, ‘maybe_restrict_ticket_option_by_cap’ ), 10, 9 );

}

public static function set_hooks_admin() {}
public static function enqueue_scripts_styles() {}
public function run( $WP ) {}

/**
* Callback for FHEE__ticket_selector_chart_template__do_ticket_inside_row filter.
* We use this to possibly replace the generated row for the current ticket being displayed in the
* ticket selector if the ticket has a required cap and the viewer does not have access to that ticket
* option.
*
* @param bool|string $return_value Either false, which means we’re not doing anything
* and let the ticket selector continue on its merry way,
* or a string if we’re replacing what get’s generated.
* @param EE_Ticket $tkt
* @param int $max Max tickets purchasable
* @param int $min Min tickets purchasable
* @param bool|string $required_ticket_sold_out Either false for tickets not sold out, or date.
* @param float $ticket_price Ticket price
* @param bool $ticket_bundle Is this a ticket bundle?
* @param string $tkt_status The status for the ticket.
* @param string $status_class The status class for the ticket.
*
* @return bool|string @see $return value.
*/
public static function maybe_restrict_ticket_option_by_cap( $return_value, EE_Ticket $tkt, $max, $min, $required_ticket_sold_out, $ticket_price, $ticket_bundle, $tkt_status, $status_class ) {
$cap_required = $tkt->get_extra_meta( ‘ee_ticket_cap_required’, true );

/*
if ( empty( $cap_required ) ) {
return false;

}
*/

//still here?
if ( ( is_admin() && ! EE_FRONT_AJAX ) || ! empty( $cap_required ) && is_user_logged_in() && EE_Registry::instance()->CAP->current_user_can( $cap_required, ‘wp_user_ticket_selector_check’ ) ) {
return false; //cap required but user has access so continue on please.
}

//check for dealsite user and hide standard tickets
if ( empty( $cap_required ) && is_user_logged_in() && !( is_admin()) ){
$current_user1 = wp_get_current_user(); //find current user
if ($current_user1->user_login === “groupon”){
return ‘ ‘;
}
}elseif( empty( $cap_required ) && is_user_logged_in() && ( is_admin())){
return false;
}elseif( empty( $cap_required ) && !is_user_logged_in()){
return false;
}
//made it here? That means user does not have access to this ticket, so let’s return a filterable message for them.
$ticket_price = empty( $ticket_price ) ? ” : ‘ (‘ . EEH_Template::format_currency( $ticket_price ) . ‘)’;
$full_html_content = ‘<td class=”tckt-slctr-tbl-td-name” colspan=”3″>’;
$inner_message = apply_filters( ‘FHEE__EED_WP_Users_Ticket_Selector__maybe_restrict_ticket_option_by_cap__no_access_msg’,
sprintf( __( ‘The %1$s%2$s%3$s%4$s is available to members only. %5$s’, ‘event_espresso’ ), ‘‘, $tkt->name(), $ticket_price, ‘‘, $tkt_status ),
$tkt,
$ticket_price,
$tkt_status
);
$full_html_content .= $inner_message . ‘</td>’;
$full_html_content = apply_filters( ‘FHEE__EED_WP_Users_Ticket_Selector__maybe_restrict_ticket_option_by_cap__no_access_msg_html’, $full_html_content, $inner_message, $tkt, $ticket_price, $tkt_status );

return $full_html_content;
}

} //end class EED_WP_Users_Ticket_Selector


jubileequeen

March 22, 2017 at 5:08 am

The code above was used when I could not get the GIST snippet of code to work. I used the standard WP_Users_Ticket_Selector.module.php file when I tried it. I renamed my custom change that I made above and gave it the extension .TXT, when I was testing your GIST snippet with the original WP_Users_Ticket_Selector.module.php.


Josh

  • Support Staff

March 22, 2017 at 9:49 am

Hi there,

Please do not directly alter EE’s core or add-on files. That will lead to breakage.

The code that Tony shared with you in that Gist will work, but it’s possible that your functions.php file from your theme is loading too late for that code to execute when the hook fires.

Instead, you can add the code snippet into a little plugin by following this guide:
https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/


jubileequeen

March 22, 2017 at 1:07 pm

I added the PHP as a plugin. Testing and enabling DEBUG.


Tony

  • Support Staff

March 22, 2017 at 1:38 pm

The first function I gave you checks for a hide_no_cap_tickets meta value on the event before removing tickets, that’s basically to prevent all of your tickets from being removed if you forget/don’t need to add a ticket with a capability on an event.

I’ve added another function to the gist which hides any tickets that don’t have a capability set and the user is logged in but doesn’t have the manage_options capability.

Try the function within functions2.php of that gist.


jubileequeen

March 31, 2017 at 9:34 pm

Thanks very much Tony. This works. I used the first function.

The support post ‘Display only the ticket type that matches the user role for ticket selector’ 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