With Event Tickets and Event Tickets Plus, events with tickets have a “Get Tickets” link that appears by default in certain places on the calendar, like list view:
There’s one in the event view as well:
Let’s say we want that to say something else, like “Register Now!” or something. Here’s a snippet that you can use to change the link text to whatever works best for your site:
Change “Register Now!” in this example to anything that you would like, then add this snippet to the `functions.php` file of your child theme, or by using the Code Snippets plugin.
PHP 7.4 version
/**
* Change the Get Tickets on List View and Single Events
*
* @param string $translation The translated text.
* @param string $text The text to translate.
* @param string $context The option context string.
* @param string $domain The domain slug of the translated text.
*
* @return string The translated text or the custom text.
*/
add_filter( 'gettext_with_context', 'tribe_change_get_tickets', 20, 4 );
function tribe_change_get_tickets( $translation, $text, $context = "" , $domain ) {
if (
$domain != 'default'
&& strpos( $domain, 'event-' ) !== 0
) {
return $translation;
}
$ticket_text = [
// Get Tickets on List View
'Get %s' => 'Register Now!',
// Get Tickets Form - Single View
'Get Tickets' => 'Register Now!',
];
// If we don't have replacement text, bail.
if ( empty( $ticket_text[ $text ] ) ) {
return $translation;
}
return $ticket_text[ $text ];
}
PHP 8.x version
/**
* Change the Get Tickets on List View and Single Events
*
* @param string $translation The translated text.
* @param string $text The text to translate.
* @param string $context The option context string.
* @param string $domain The domain slug of the translated text.
*
* @return string The translated text or the custom text.
*/
add_filter( 'gettext_with_context', 'tribe_change_get_tickets', 20, 4 );
function tribe_change_get_tickets( string $translation, string $text, string $context, string $domain ): string {
if (
$domain != 'default'
&& ! str_starts_with( $domain, 'event-' )
) {
return $translation;
}
$ticket_text = [
// Get Tickets on List View
'Get %s' => 'Register Now!',
// Get Tickets Form - Single View
'Get Tickets' => 'Register Now!',
];
// If we don't have replacement text, bail.
if ( empty( $ticket_text[ $text ] ) ) {
return $translation;
}
return $ticket_text[ $text ];
}
Note, $context
and $domain
parameters are not used in the above example, so they can be omitted. If so, remember to change the number of parameters from 4 to 2 when applying the filter.