Skip to content

Instantly share code, notes, and snippets.

@Pebblo Pebblo/example.php
Last active Sep 4, 2017

What would you like to do?
Example of how to translate the sold out message shown on the event in place of the ticket selector.
<?php //Please do not include the opening PHP tag if you already have one
function mycustom_filter_gettext( $translated, $original, $domain ) {
// This is an array of original strings
// and what they should be replaced with
$strings = array(
'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s' => '%1$sSorry, "%2$s" is currently sold out.%4$sPlease check back again later.%3$s',
'Sold&nbsp;Out' => 'Fully&nbsp;Booked',
// 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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.