Skip to content

Instantly share code, notes, and snippets.

@benhuson
Created January 17, 2013 15:04
Show Gist options
  • Save benhuson/4556545 to your computer and use it in GitHub Desktop.
Save benhuson/4556545 to your computer and use it in GitHub Desktop.
How to filter translated text in WordPress This example shows how to filter the 'This product has sold out.' text in the WP e-Commerce plugin. If the translation domain is 'wpsc' it will replace the text with 'This product is no longer available.'.
<?php
/**
* This example shows how to filter the 'This product has sold out.' text.
* If the translation domain is 'wpsc' it will replace the text with 'This product is no longer available.'.
*/
add_filter( 'gettext', 'my_gettext_filter' );
function my_gettext_filter( $translated_text, $text, $domain ) {
if ( 'wpsc' == $domain ) {
switch ( $text ) {
case 'This product has sold out.' :
$translated_text = __( 'This product is no longer available.', 'my_domain' );
break;
}
}
return $translated_text;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment