Support

Home Forums Event Espresso Premium Trying to change text On Sale

Trying to change text On Sale

Posted: August 17, 2017 at 11:18 pm


solwebsolutions

August 17, 2017 at 11:18 pm

On our page:
https://www.lafsn.org/wp/calendar/gingerbread-house-building/

I’ve got the wording almost correct, but we want the “On Sale” string in green to be “Login Now”. I’m using this code but it’s not updating the “On Sale” string:

//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function mycustom_filter_gettext( $translated, $original, $domain ) {
 
    // This is an array of original strings
    // and what they should be replaced with
    $strings = array(
        'The %1$s%2$s%3$s%4$s  is available to members only. %5$s' => 'The %1$s%2$s%3$s%4$s  is only available to sponsors. %5$s',
'On Sale' => 'Login Now',
        // Add some more strings here
    );
 
    // See if the current string is in the $strings array
    // If so, replace its translation
    if ( isset( $strings[$original] ) ) {
        // This accomplishes the same thing as __()
        // but without running it through the filter again
        $translations = get_translations_for_domain( $domain );
        $translated = $translations->translate( $strings[$original] );
    }
 
    return $translated;
}
 
add_filter( 'gettext', 'mycustom_filter_gettext', 10, 3 );

Please advise…thank you!

  • This topic was modified 6 years, 8 months ago by  Tony. Reason: code formatting


Tony

  • Support Staff

August 18, 2017 at 4:11 am

Hi there,

That text is actually lower case within the code so you’ll need:

'on sale' => 'Login Now',

However, doing the above you going to change the ticket state ‘on sale’ everywhere on your site which I don’t think is what you will want.

You’re already translating the string that outputs that text so you can change it there.

'The %1$s%2$s%3$s%4$s is available to members only. %5$s' => 'The %1$s%2$s%3$s%4$s is only available to sponsors. %5$s',

Could be:

'The %1$s%2$s%3$s%4$s is available to members only. %5$s' => 'The %1$s%2$s%3$s%4$s is only available to sponsors. Login Now',

That won’t have the text in green, but you can also add another span to the string you can use to style the text if preferred?


solwebsolutions

August 21, 2017 at 7:26 pm

Thank you…that worked!

The support post ‘Trying to change text On Sale’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso