Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewlimaza/e781af196ff8cf4894be9155a1cde6c5 to your computer and use it in GitHub Desktop.
Save andrewlimaza/e781af196ff8cf4894be9155a1cde6c5 to your computer and use it in GitHub Desktop.
PMPro add custom fields to email
<?php
/**
* This recipe Adds !!company!!/!!phone!! as an available variable for use in Paid Memberships Pro emails.
* When the variable is empty it will display nothing instead of the !!company!!/!!phone!! email variable
*
* Notice the array key does not include the !!s
*
* 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_email_data( $data, $email ) {
global $current_user;
$company = get_user_meta( $current_user->ID, 'company', false );
$phone = get_user_meta( $current_user->ID, 'phone', false );
if ( empty( $company ) ) {
$company = ''; // display nothing for email ariable !!company!! if empty.
}
if ( empty( $phone ) ) {
$phone = ''; // display nothing for email ariable !!phone!! if empty.
}
$data['company'] = $company;
$data['phone'] = $phone;
return $data;
}
add_filter( 'pmpro_email_data', 'my_pmpro_email_data', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment