Home › Forums › Ticket Products › Event Tickets Plus › Rewording "tickets left" to "places left"
- This topic has 12 replies, 3 voices, and was last updated 7 years, 11 months ago by
thereelscene.
-
AuthorPosts
-
May 22, 2018 at 6:06 am #1535915
thereelscene
ParticipantHi Guys
I’ve read the previous ticket on this topic, basically how to reword “ticket” to something else like “place”.
Using the Change the wording of any bit of text or string snippet didn’t work, as the text “%s places left” in tickets.php doesn’t seem to use gettext() – line 220, /event-tickts/src/template-tags/tickets.php
if ( 'rsvp' === $type ) { $text = _n( '%s spot left', '%s spots left', $stock, 'event-tickets' ); } else { $text = _n( '%s ticket left', '%s tickets left', $stock, 'event-tickets' ); } $stock_html = '<span class="tribe-tickets-left">' . esc_html( sprintf( $text, $number ) ) . '</span>';Is it possible to make a modified copy of this file as is done with other templated files in /src/view? or is there another way to make this sort of change?
Cheers
May 22, 2018 at 8:07 pm #1536715Cliff
MemberHi. Thanks for your detailed request. Please provide the whole code snippet, including the add_filter(), and I will try to sort this out for you.
May 23, 2018 at 2:08 am #1536838thereelscene
ParticipantThanks Cliff, here’s the code at the top of the child theme functions file:
function tribe_custom_theme_text ( $translation, $text, $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 // This example changes the label "Venue" to "Location", and "Related Events" to "Similar Events" $custom_text = array( '%s ticket left' => '%s place left', '%s tickets left' => '%s places left' ); // If this text domain starts with "tribe-", "the-events-", or "event-" and we have replacement text if( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) && array_key_exists($translation, $custom_text) ) { $translation = $custom_text[$translation]; } return $translation; } add_filter('gettext', 'tribe_custom_theme_text', 20, 3);Cheers
May 24, 2018 at 11:51 pm #1538509Cliff
MemberThanks!
I believe you’ll need to use the ngettext filter instead: https://developer.wordpress.org/reference/hooks/ngettext/
This is because you’re filtering something from _n()
Please reference that documentation link and let me know if you can’t figure out how to proceed.
May 31, 2018 at 11:33 pm #1543607kaleido
Participantthereelscene,
did you ever get your code worked out for rewording “tickets left” to “places left”? I’ve been trying to figure this out as well. I tried all the suggestions on the same threads you mentioned, but nothing works.
Any insight on this would be much appreciated.
June 1, 2018 at 1:45 am #1543640thereelscene
ParticipantHi
No, I haven’t yet, ngettext() has different parameters to gettext() so I need to rewrite that code snippet but haven’t gotten round to doing it yet, I”ll post it when I get it working 🙂
Cheers
June 1, 2018 at 10:15 pm #1544444Cliff
MemberHopefully this example snippet helps both of you:
https://gist.github.com/cliffordp/a35f07f81aa14fbf0bca373dd97d9ede
Please reference https://theeventscalendar.com/knowledgebase/implementing-custom-code-snippets/ for how to implement custom code snippets.
Please let me know how this goes for you.
June 2, 2018 at 5:21 pm #1544756kaleido
ParticipantHey thereelscene,
I found a post that really helped out a lot and I was about to get this working for the site I’m working on. Here’s a link to the page: https://webandprosper.co.uk/events-calendar-pro-custom-photo-view/Below is the code I used. I haven’t had any issues with it so far.
I hope you find this helpful.//TARGETS NUMBER OF TICKETS AND REPLACES WITH PLACES add_filter( 'tribe_tickets_buy_button', 'changes_button_text', 11, 2 ); function changes_button_text( $html ) { $html = str_replace("tickets left", "seats left", $html); $html = str_replace("ticket left", "seat left", $html); return $html; } /* * EXAMPLE OF CHANGING ANY TEXT (STRING) IN THE EVENTS CALENDAR * See the codex to learn more about WP text domains: * http://codex.wordpress.org/Translating_WordPress#Localization_Technology * Example Tribe domains: 'tribe-events-calendar', 'tribe-events-calendar-pro'... */ function tribe_custom_theme_text ( $translations, $text, $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 // This example changes the label "Venue" to "Location", and "Related Events" to "Similar Events" $custom_text = array( //'Photo' => 'Grid', //'Month' => 'Calendar', 'Buy Now!' => 'Book Now!', 'Buy Now' => 'Book Now', ); // If this text domain starts with "tribe-" or "the-events-", and we have replacement text if((strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) && array_key_exists($text, $custom_text) ) { $text = $custom_text[$text]; } return $text; } add_filter('gettext', 'tribe_custom_theme_text', 20, 3);June 3, 2018 at 4:51 am #1544895Cliff
Member@kaleido, thanks for sharing what worked for you. Filtering tribe_tickets_buy_button should work just fine as well–a good alternative, albeit with a bit less control if someone’s translation wanted to handle specific quantities (e.g. zero) distinctly.
@thereelscene, as this is your thread, please let me know if this topic is resolved or if you need more assistance.June 3, 2018 at 11:30 am #1545022thereelscene
ParticipantHi Cliff
It hasn’t worked for me. I’ve added it to the top of functions.php in the child theme. I tried changing
if ( 'event-tickets' === $domain ) {to
if( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) ) {But now on the events page in list view I get, for example “16 ticket left”, so something is wrong somewhere lol. I will keep looking and let you know if I find a solution.
Cheers
June 5, 2018 at 3:03 pm #1546863Cliff
MemberSorry about that. I updated the snippet and tested that it’s working now.
Here’s a screenshot: https://cl.ly/1j2G372T0f11
Please let me know how this goes for you.
June 6, 2018 at 1:20 am #1547136thereelscene
ParticipantThat did the trick! Thanks!
June 6, 2018 at 4:10 pm #1547968Cliff
MemberGlad to hear! Thanks for letting me know.
-
AuthorPosts
- The topic ‘Rewording "tickets left" to "places left"’ is closed to new replies.
