Last active
December 4, 2023 08:57
-
-
Save andrewlimaza/20ca1baa7696b8e884f42b4c8446d659 to your computer and use it in GitHub Desktop.
Translate Email / Change email content based on different locale for PMPro.
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 | |
/** | |
* | |
* ===== WARNING ===== | |
* This code recipe is intended for developers and requires extensive knowledge of websites, and WordPress. | |
* Copying and pasting this recipe into your site as-is won't work - you need to follow the steps outlined in this code. | |
* If you are unsure, please hire a local WordPress developer or freelance for assistance. | |
* | |
* This code recipe was built for private use, outside of Paid Memberships Pro and it's support scope. | |
* =================== | |
* | |
* | |
* 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 = get_locale(); | |
// If the default locale (in this case en_US) is not loaded, try to switch out the email templates. | |
if ( strpos( $locale, 'en_US' ) == 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
Please use this gist with care, if further help is needed in configuring and setting this up please reach out to a local WordPress developer or freelancer.