cliff
6/2/2018 - 5:10 AM

Event Tickets: Customize the "spots left" / "tickets left" texts. Uses 'ngettext' filter.

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 );