Created
June 8, 2016 19:53
-
-
Save joshfeck/4028f3345d69bd312862b64b94f07e26 to your computer and use it in GitHub Desktop.
A few examples that show how to translate text strings that display in Event Espresso's checkout. These examples use specific filter hooks where available and also the general gettext filter hook.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
// registration button text | |
function ee_modify_button_text( $submit_button_text, EE_Checkout $checkout ) { | |
if ( ! $checkout instanceof EE_Checkout || ! $checkout->current_step instanceof EE_SPCO_Reg_Step || ! $checkout->next_step instanceof EE_SPCO_Reg_Step ) { | |
return $submit_button_text; | |
} | |
if ( $checkout->next_step->slug() == 'finalize_registration' ) { | |
$submit_button_text = 'Finalize registration · Finaliser inscription'; | |
} | |
return $submit_button_text; | |
} | |
add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_modify_button_text', 10, 2); | |
// promotion button text | |
function ee_modify_promotions_button_text() { | |
return 'Submit Promotion Code · Soumettre le code de Promotion'; | |
} | |
add_filter( 'FHEE__EED_Promotions___add_promotions_form_inputs__ee_promotion_code_submit__default', 'ee_modify_promotions_button_text' ); | |
// general text strings | |
function ee_general_filter_gettext( $translated, $original, $domain ) { | |
// This is an array of original strings | |
// and what they should be replaced with | |
$strings = array( | |
'Please Select Your Method of Payment' => 'Please Select Your Method of Payment · Merci de sélectionner votre mode de règlement', | |
'Important information regarding your payment' => 'Important information regarding your payment · Information importante à propos de votre paiement', | |
'First Name' => 'First name · Prénom', | |
'Last Name' => 'Last name · Nom de famille', | |
// 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', 'ee_general_filter_gettext', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment