Support

Home Forums Event Espresso Premium list of filter functions to change text?

list of filter functions to change text?

Posted: September 13, 2021 at 6:43 pm


BCPTA

September 13, 2021 at 6:43 pm

Hello,
I am trying to change the word “Upcoming” to something else, and the words “on sale” to something else.

I saw this post https://eventespresso.com/topic/change-goes-on-sale-text/

Is there a list of functions somewhere? I couldn’t find this by searching documentation.

I saw other posts saying to translate from English to English. I’m really hoping for an easier way to do this since it’s so little we want to change.

When I added this code to my functions.php file the site said “There has been a critical error on this website.”

I’m not a coder and maybe that was incorrect (it seemed templated). But any guidance you can offer would be helpful, thank you.


Tony

  • Support Staff

September 14, 2021 at 9:38 am

Hi there,

Which specific ‘Upcoming’ and ‘on sale’ string are you looking to change?

To clarify in case it isn’t clear, you can’t change ALL instances of a string by using a partial translation. Meaning although you mentioned you want to change ‘on sale’, is that to change the ‘Goes on sale’ string? As you’d need to target that whole specific string and just ‘on sale’.

Copying the code from the forums can be tricky as there’s formatting here which will then throw a fatal error as above.

If you let me know the specific strings you are looking to change I’ll help point you in the right direction for doing so 🙂


BCPTA

October 14, 2021 at 4:16 pm

Hello this is in follow up to https://eventespresso.com/topic/list-of-filter-functions-to-change-text/

Sorry we can not reply fast enough to the time you need to close topics. We are mostly volunteer run and have a contractor working with us who is not full time with us. We wrote about this before. It would be helpful if we could re-open threads on our end, or have more time to reply.

Anyway, in follow up to the previous question,

We would like to change all of the instances of “Upcoming” on the events to “Registration Open.” In other words, on the archive pages of events. I don’t have an example to show you now because due to covid, we don’t have in-person events right now (only online). They all say “expired.” But where it says “expired” is where it would normally say “Upcoming” if the event were “Upcoming”. Here is an example: https://cloudup.com/cNZM5ovzVhX

The word “on sale” in order to buy a ticket to an event sounds like a discount. We just want it to say “Log in to access” since it applies to our member tickets: https://cloudup.com/cVBBA5XgB-K

Thank you very much for all your help.


Tony

  • Support Staff

October 15, 2021 at 5:03 am

Hi there,

Sorry we can not reply fast enough to the time you need to close topics. We are mostly volunteer-run and have a contractor working with us who is not full time with us. We wrote about this before. It would be helpful if we could re-open threads on our end, or have more time to reply.

No apology needed, just open up a new thread with reference to the old one and we can re-open and merge (which I have done here).

Threads automatically close after 2 weeks of no activity from the last reply date, that value is set globally so I can’t change that to give you specifically more time to reply.

To explain a little on why threads close, we try to keep threads on a specific topic and if we then allow users to reopen them again it would be pointless having them close at all. We’ve seen in the past some threads running across multiple different issues, mixing and matching problems/solutions and cross-referencing issues from earlier which just gets confusing for all in the end. So we prefer to keep threads on topic and handle each specific issue within that thread as much as we can and then close it, users being able re-opening threads and adding new issues to current threads just creates more confusion and more work on our end for little benefit.

We would like to change all of the instances of “Upcoming” on the events to “Registration Open.” In other words, on the archive pages of events. I don’t have an example to show you now because due to covid, we don’t have in-person events right now (only online). They all say “expired.” But where it says “expired” is where it would normally say “Upcoming” if the event were “Upcoming”. Here is an example: https://cloudup.com/cNZM5ovzVhX

Ok, so that’s the event status banner and I should add here that an ‘Upcoming’ event may not always have tickets on sale which means ‘Registration Open’ would not be correct.

Changing that status can be done using a snippet like this:

https://gist.github.com/Pebblo/5da1f1d8882ffac6925a332a8911d73e

For EE_Datetime::upcoming you could have something like:

$translation_array[EE_Datetime::upcoming] = array(
    'registration open', //singular
    __('upcoming', 'event_espresso'), //plural
);

The others can be removed if preferred but the above is what set the status string for ‘Upcoming’.

The word “on sale” in order to buy a ticket to an event sounds like a discount. We just want it to say “Log in to access” since it applies to our member tickets: https://cloudup.com/cVBBA5XgB-K

That’s using the ticket ‘on sale’ status, you could use the above snippet to change that by changing the strings for singular and plural like above:

$translation_array[EE_Ticket::onsale] = array(
    esc_html__('on sale', 'event_espresso'), //singular
    esc_html__('on sale', 'event_espresso'), //plural
);

This would go in as part of the above snippet and change the ‘On Sale’ status sitewide, however, as you’ve mentioned you want to use ‘Log in to access’ I’m assuming you want to only change that specific string in the image and we have a filter for that:

FHEE__EED_WP_Users_Ticket_Selector__maybe_restrict_ticket_option_by_cap__no_access_msg

Here is an example of using that filter to change the text:

https://gist.github.com/Pebblo/783dc4f9f43b9780d860112817edfd6d


BCPTA

October 18, 2021 at 7:08 pm

Hello thank you for your help and explanations.

I tried this bit of code in functions.php:

$translation_array[EE_Datetime::upcoming] = array(
    'registration open', //singular
    __('upcoming', 'event_espresso'), //plural
);

–> the above changed nothing.

As well as this:

add_filter('FHEE__EEM_Status__localized_status__translation_array', 'ee_tw_localized_status__translation_array');
function ee_tw_localized_status__translation_array( $translation_array ) {
    //Upcoming
    $translation_array[EE_Datetime::upcoming] = array(
        __('Registration open', 'event_espresso'), //singular
        __('upcoming', 'event_espresso'), //plural
    );
    }

–> The above resulted in https://cloudup.com/c9fg-o9I44Q
It says “Unkonwn” instead of “registration open”. It also changes “on sale” to “unknown.”

I’m sorry I’m not a full-on coder like this. Can you help us solve this?

Then, I tried this bit of code:

add_filter('FHEE__EEM_Status__localized_status__translation_array', 'ee_tw_localized_status__translation_array');
function ee_tw_localized_status__translation_array( $translation_array ) {
    //Upcoming
    $translation_array[EE_Datetime::upcoming] = array(
        __('Registration open', 'event_espresso'), //singular
        __('upcoming', 'event_espresso'), //plural
    );
    }

It removes the entire line of member pricing ticket, and replaces it with the text above (i.e. to say “Click here to become a member.”) We need the ticket and everything to stay there, but we want the word “on sale” to change to “log in to access” if it requires that to be able to purchase it.

Here is a screenshot: https://cloudup.com/cQAngMcVTB4

Can you help us with this also?

This is what it looks like without any code added to the functions.php file https://cloudup.com/ckkU6R4mVJ8

Thank you again, we really appreciate it.


BCPTA

October 18, 2021 at 7:34 pm

Nevermind about changing “on sale”. I figured out the other example in the link you sent does work. I used it as follows:

function tw_change_access_message( $original_text, $ticket, $ticket_price, $ticket_status ) {
    return sprintf( 
        '<strong>%1$s%2$s%3$s%4$s. %6$sLog-in to access%7$s.</strong>',
		'<strong>',
        $ticket->name(),
        $ticket_price,
        '</strong>',
        $ticket_status,
	'<a href="https://www.bcplaytherapy.ca/login/">',
	'</a>'
    );
	
}
add_filter('FHEE__EED_WP_Users_Ticket_Selector__maybe_restrict_ticket_option_by_cap__no_access_msg', 'tw_change_access_message', 10, 4);

The thing I just can’t understand is why, if I move '<strong>', before the 'log in to access'%1$s%2$s%3$s%4$s. %6$sLog-in to access%7$s.‘,` line, or if I take out my own addition of on that line, it just doesn’t show up at all. Seems strange to me to have two strong tags for no reason. But anyway, it works.

I’m still having trouble with the “Upcoming” message.

Thank you again.


Tony

  • Support Staff

October 19, 2021 at 3:14 am

Apologies, as you were asking for a list of filters I assumed you were familiar with using them so didn’t go into details.

When using a filter you are basically given ‘something’ passed into the filter which you can then change and return back so that it uses your changes. So for changing ‘upcoming’ to ‘registration open’ you need to change the values and then return the array.

Something like this:

https://gist.github.com/Pebblo/6405639765420c31e2ec976b15220105

Note that Event Espresso automatically adds capitalization when needed so you can use all lower case.

The thing I just can’t understand is why, if I move ‘‘, before the ‘log in to access’‘%1$s%2$s%3$s%4$s. %6$sLog-in to access%7$s.‘,` line, or if I take out my own addition of on that line, it just doesn’t show up at all. Seems strange to me to have two strong tags for no reason. But anyway, it works.

I’m not sure I follow, but to explain a little more on how the above works the sprintf() function takes a string and then replace any ‘placeholders’ within that string with the values passed to it.

So %1$s is a placeholder for the ‘first’ string (a string being a collection of characters) passed to the function.

%2$s being the second and so on.

So my function has:

return sprintf(    
    'You must login as a member to view the %1$s%2$s%3$s%4$s option. Log-in %6$shere%7$s.',
    '<strong>', //%1$s
    $ticket->name(), //%2$s
    $ticket_price,  //%3$s
    '</strong>', //%4$s
    $ticket_status, //%5$s
    '<a href="https://www.example.com/your-profile/login/">', //%6$s
    '</a>' //%7$s
);

So now knowing how the above function works, you know the string looks more like:

You must login as a member to view the <strong>{ticket_name}{ticket_price}</strong> option. Log-in <a>here</a>.

(I’ve skipped the full URL in the above example, but I think it shows enough to see what is happening)

So if you just want the full string to be strong use the place holders in the correct locations to do that correctly like this:

%1$sYou must login as a member to view the %2$s%3$s option. Log-in %6$shere%7$s.%4$s

Does that help?

The support post ‘list of filter functions to change text?’ 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