Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active May 13, 2021 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/a35f07f81aa14fbf0bca373dd97d9ede to your computer and use it in GitHub Desktop.
Save cliffordp/a35f07f81aa14fbf0bca373dd97d9ede to your computer and use it in GitHub Desktop.
Event Tickets: Customize the Buy Now button's "spots left" / "tickets left" texts. Screenshot: https://cl.ly/1j2G372T0f11
<?php
/*
* Event Tickets: Customize the Buy Now button's "spots left" / "tickets left" texts.
*
* Screenshot: https://cl.ly/1j2G372T0f11
* Uses 'ngettext' filter.
*
* @link https://gist.github.com/cliffordp/a35f07f81aa14fbf0bca373dd97d9ede This snippet.
* @link https://github.com/moderntribe/event-tickets/blob/4.7.2/src/template-tags/tickets.php#L221-L223 The text we are customizing.
* @link https://theeventscalendar.com/support/forums/topic/rewording-tickets-left-to-places-left/ Help Desk request.
* @link https://theeventscalendar.com/knowledgebase/change-the-wording-of-any-bit-of-text-or-string/ How to use 'gettext' filter for other strings.
*
* @see tribe_tickets_buy_button()
* @see number_format_i18n()
*
* @param string $translation Translated text.
* @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural.
* @param string $number The number to compare against to use either the singular or plural form.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*
* @return string
*/
function cliff_et_custom_spots_tickets_texts( $translation, $single, $plural, $number, $domain ) {
if ( 'event-tickets' === $domain ) {
// Put your custom text here in a key => value pair
// Example: 'Text you want to change' => 'This is what it will be changed to'
// The text you want to change is the key, and it is case-sensitive
// The text you want to change it to is the value
// You can freely add or remove key => values, but make sure to separate them with a comma
$custom_text = array(
'%s spot left' => '%s RSVPPPPP left',
'%s spots left' => '%s RSVPPPPPs left',
'%s ticket left' => '%s Placeeee left',
'%s tickets left' => '%s Placeeees left',
);
foreach ( $custom_text as $key => $value ) {
if ( $key === $translation ) {
$translation = $value;
break;
}
}
}
return $translation;
}
add_filter( 'ngettext', 'cliff_et_custom_spots_tickets_texts', 20, 5 );
@rayzistdev
Copy link

Not functioning

@cliffordp
Copy link
Author

I'm guessing it's outdated and that https://theeventscalendar.com/knowledgebase/k/changing-the-buy-now-button-text/ is the info you are wanting. If not: support.theeventscalendar.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment