Support

Home Forums Events Calendar Add-on EE4 Edit Sold Out [ticket selector] Message – custom filter

EE4 Edit Sold Out [ticket selector] Message – custom filter

Posted: May 2, 2017 at 10:33 am


mattbru

May 2, 2017 at 10:33 am

EE4 v4.9.29.p / wp v4.7.4

Hi. I have attempted to use the filter
FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg
to update the ticket selector message. The default is :
<p class=”no-ticket-selector-msg clear-float”>”Event Name” is currently sold out.<br>Please check back again later, as spots may become available.</p>

I found the filter name inside DisplayTicketSelector.php file, line 515.

                    $html .= apply_filters(
                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
                        sprintf(
                            __(
                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
                                'event_espresso'
                            ),
                            '<p class="no-ticket-selector-msg clear-float">',
                            $this->event->name(),
                            '</p>',
                            '<br />'
                        ),
                        $this->event
                    );

… and my attempt at creating a filter is as follows:


function ee4_change_sold_out_msg($string){
	$string = $this->event->name() . ' is currently sold out. Please <a href="mailto:info@site.com" target="_blank">email us</a> to join a cancellation list.';
    return $string;
}
add_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', 'ee4_change_sold_out_msg', 55 );

Could you please give me an idea of what needs to happen? Maybe i need to pass a global $event variable through and use it somehow?

Thank you!
Matt


Josh

  • Support Staff

May 2, 2017 at 10:56 am

Hi Matt,

Actually you’ll need to pass in the accepted arguments in your function and specify the number of accepted args. Here’s an example from the codex:

https://developer.wordpress.org/reference/functions/add_filter/#comment-407

So your code should end up something like this:

function ee4_change_sold_out_msg( $string, $this->event ){
	$string = $this->event->name() . ' is currently sold out. Please <a href="mailto:info@site.com" target="_blank">email us</a> to join a cancellation list.';
    return $string;
}
add_filter( 
'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
'ee4_change_sold_out_msg', 
11, 
2 
);


mattbru

May 2, 2017 at 12:22 pm

Hi Josh.
Thanks for your reply!
Okay, now this works:


if( ! function_exists( 'ee4_change_sold_out_msg' ) ) {
	function ee4_change_sold_out_msg($string){
		$string = 'This is currently sold out. Please <a href="mailto:info@site.com" target="_blank">email us</a> to join a cancellation list.';
		return $string;
	}
}
add_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', 'ee4_change_sold_out_msg', 12, 1 );

But I cannot just reference $this inside the function or as a parameter. I assume it is because the function doesnt know what object $this is referring to. Do you have any examples of other ee4 filter functions using the current event in the loop and accessing things like permalink and event name, etc. I am using this on the single page and assume it is within the loop.

Many thanks!
Matt


mattbru

May 2, 2017 at 12:53 pm

Finally figured it out!

Here is my solution:


if( ! function_exists( 'ee4_change_sold_out_msg' ) ) {
	function ee4_change_sold_out_msg($string, $event){
		$event_name = $event->get('EVT_name');
		$string = $event_name . ' is currently sold out. Please <a href="mailto:info@site.com" target="_blank">email us</a> to join a cancellation list.';
		return $string;
	}
}
add_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', 'ee4_change_sold_out_msg', 12, 2 );

I completley guessed on passing in the $event object. Then I printr($event) and saw EVT_name inside the object, and found the get method to obtain the name. Not very obvious right way, but I finally got it.

Thanks for pointing me in the right direction Josh. You can mark this closed.
Matt


Josh

  • Support Staff

May 2, 2017 at 1:24 pm

Hey Matt,

You’re correct about not being able to reference this, but you can access the event object. Corrected code follows:

function ee4_change_sold_out_msg( $string, $event_object ){
  $string = $event_object->name() . ' is currently sold out. Please <a href="mailto:info@site.com" target="_blank">email us</a> to join a cancellation list.';
    return $string;
}
add_filter( 
'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
'ee4_change_sold_out_msg', 
11, 
2 
);

Do you have any examples of other ee4 filter functions using the current event in the loop and accessing things like permalink and event name, etc. I am using this on the single page and assume it is within the loop.

The best place to look is within the core plugin, in the public folder you’ll see a bunch of templates with event in their name.

The support post ‘EE4 Edit Sold Out [ticket selector] Message – custom filter’ 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.

Status: closed

Updated by  Josh 2 years, 4 months ago ago

Topic Tags

Tagged: ,

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!