Posted: June 4, 2018 at 11:49 am
|
Hi, I’m using Tony’s script from : https://gist.github.com/Pebblo/a68e8a151bd1df0288c45ddff585c300 to try and change some of the default EE text, but it isn’t working as I would have expected. It changed the text on the simple event list register button from “Sold Out” to “Class Full”, but on a “members only” event page it is not replacing “The [ticket] is available to members only.” with “The [ticket] is restricted.” Will this script not work for this text (no-tkt-slctr-ticket-content-dv)? Ideally, I’d like the restricted ticket text to say “This course is restricted to [capability],” (since I imagine that variable can be pulled), and then I’d use the filter/replace script to switch that text out as well; e.g. “level_4” => “Level 4 employees.” |
The script will work if you have an exact match of the original string. Do you have this set as the original string?
|
|
|
I did not, but I tried it and it didn’t change anything. Below is the germane part…
|
|
I copied and pasted that portion of text from Tony’s original post, and it’s working now. Is there a hook (?) for the restricted capability, e.g. ‘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 restricted to [level_4]’, |
There is a filter hook that makes the capability available, but it works differently than how you’re using the
|
|
|
That works – but it still displays the format restricted version of the capability (e.g. level_4 vs. Level 4). I tried adding ‘level_4’ => ‘Level 4’ to the other script, but that didn’t work. That’s okay, fixing the main string replace was my primary goal. Thanks Josh! |
You can reformat the way the capability is displayed by adding a bit more PHP code. For example, make the changes to the above code:
|
|
|
So this is how I interpreted that change:
But it didn’t do anything, so I missed something. Also, I had no idea what a switch statement was, but I looked it up on w3schools and took a stab:
Am I close? |
That’s a good crack at it. One important thing to remember is you generally do not Before we tackle the switch statement, is the WordPress capability that’s required for the ticket
|
|
|
metro_transit is the capability (to be displayed as Metro Transit). I used “level_4” just as a generic placeholder. |
Maybe what you could do is add a little temporary debugging code to your custom code like this:
then, you can copy and paste the debug output and use that in your conditional statement. |
|
|
I think I misinterpreted your previous question what is currently displaying. Here’s the full code I have active now, to include the debugging line you just gave me. (Also worth mentioning, I really don’t know php; I’m just marginally decent at adapting existing code for my purposes).
|
Is anything being output onto the screen by |
|
|
Nothing different than before. It says “The [ticket name] is restricted to designated personnel.” |
OK on a closer look there’s a missing closing bracket in one place and an extra closing bracket in another. In any case, here’s an altered version of with some suggested fixes: https://gist.github.com/joshfeck/bb977b3cc27a5ffa619761430a65ff14 |
|
|
That’s a perfect fix. The underscore replace is a much more svelt solution than switch. Thanks for your help Josh! |
|
…for the benefit of others that might need a similar solution in the future, I added the second line, which capitalizes the hooked capability [placed after $cap_required_display_name = str_replace( $search, $replace, $cap_required);]
|
The support post ‘Replace Text on Event Page Script Not Working’ 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.