Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JarrydLong/f4f62cc59781eda7d9ff770b263542fe to your computer and use it in GitHub Desktop.
Save JarrydLong/f4f62cc59781eda7d9ff770b263542fe to your computer and use it in GitHub Desktop.
Translate Email / Change email content based on different locale for PMPro.
<?php
/**
* Adjust email content based on locale used on checkout. Works with WPML plugin.
* This requires a couple of steps to get working.
* 1. Inside your PMPro Customizations Plugin, create a folder called email_fr_FR
* (You may change fr_FR to the locale your site will be serving besides the default locale - create as many folders that you need).
* 2. Copy the email templates from 'wp-content/plugins/paid-memberships-pro/email' and paste them into your email_fr_FR folder created above.
* 3. Manually edit each template with the translation of the emails or adjust the email template to your liking.
* 4. Repeat these steps for each email folder you created depending on the number of locales your site is using.
* 5. Paste the code below into your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_change_email_body_based_on_locale( $body, $email ) {
$locale = apply_filters( 'wpml_current_language', null );
// If the default locale (in this case en) is not loaded, try to switch out the email templates.
if ( strpos( $locale, 'en' ) == false ) {
// let's use the following template then.
$body = file_get_contents( plugin_dir_path( __FILE__ ) . 'email_' . $locale . '/' . $email->template . '.html');
}
return $body;
}
add_action( 'pmpro_email_body', 'my_pmpro_change_email_body_based_on_locale', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment