Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created May 21, 2024 09:38
Show Gist options
  • Save ipokkel/667ff599fb06e9d9becd1e7b9e03d50d to your computer and use it in GitHub Desktop.
Save ipokkel/667ff599fb06e9d9becd1e7b9e03d50d to your computer and use it in GitHub Desktop.
<?php
/**
* Replace email variables with data in PMPro emails.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_replace_email_variables_with_data( $email ) {
// Let's check for any remaining email variables and replace them with the data.
if ( is_array( $email->data ) ) {
foreach ( $email->data as $key => $value ) {
if ( 'body' != $key ) {
$email->body = str_replace( '!!' . $key . '!!', $value, $email->body );
$email->subject = str_replace( '!!' . $key . '!!', $value, $email->subject );
}
}
}
return $email;
}
add_filter( 'pmpro_email|_filter', 'my_pmpro_replace_email_variables_with_data', 99, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment