Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewlimaza/129c7571113152ba6522c190cac728df to your computer and use it in GitHub Desktop.
Save andrewlimaza/129c7571113152ba6522c190cac728df to your computer and use it in GitHub Desktop.
Add multiple Custom Fields to Email for Paid Memberships Pro with Attributes.
<?php
/**
* Add this code (line 8-32) to your PMPro Customizations Plugin.
* Inside your checkout email for members/admins, add any attributes and it will replace the value if there is a value available.
* E.g Your number is !!mobile!!, see line 24 for all available attributes to use in Email Template Admin Editor
*/
function my_pmpro_email_body( $body, $email ) {
//only checkout emails
if ( false !== strpos( $email->template, "checkout" ) ) {
// Get the user first.
$user = get_user_by( 'email', $email->data['user_email'] );
// Get all custom fields for user checkout.
$mobile = get_user_meta( $user->ID, 'Mobile', true );
$dob = get_user_meta( $user->ID, 'dob', true );
$my_nickname = get_user_meta( $user->ID, 'my_nickname', true );
$mail_format = get_user_meta( $user->ID, 'mail_format', true );
$appropriate = get_user_meta( $user->ID, 'appropriate', true );
$hear_about_us = get_user_meta( $user->ID, 'hear_about_us', true );
//Create an array of attributes, this will act as needle.
$attributes = array('!!mobile!!', '!!dob!!', '!!nickname!!', '!!mail_format!!', '!!appropriate!!', '!!hear_about_us!!');
$replaced_values = array( $mobile, $dob, $my_nickname, $mail_format, $appropriate, $hear_about_us );
$body = str_replace( $attributes, $replaced_values, $body );
}
return $body;
}
add_filter( "pmpro_email_body", "my_pmpro_email_body", 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment