Rewording "tickets left" to "places left"

Home Forums Ticket Products Event Tickets Plus Rewording "tickets left" to "places left"

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1535915
    thereelscene
    Participant

    Hi 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

    #1536715
    Cliff
    Member

    Hi. 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.

    #1536838
    thereelscene
    Participant

    Thanks 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

    #1538509
    Cliff
    Member

    Thanks!

    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.

    #1543607
    kaleido
    Participant

    thereelscene,

    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.

    #1543640
    thereelscene
    Participant

    Hi

    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

    #1544444
    Cliff
    Member

    Hopefully 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.

    #1544756
    kaleido
    Participant

    Hey 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);
    #1544895
    Cliff
    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.

     

    #1545022
    thereelscene
    Participant

    Hi 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

    #1546863
    Cliff
    Member

    Sorry 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.

    #1547136
    thereelscene
    Participant

    That did the trick! Thanks!

    #1547968
    Cliff
    Member

    Glad to hear! Thanks for letting me know.

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘Rewording "tickets left" to "places left"’ is closed to new replies.