Forked from ipokkel/pmpro-add-custom-fields-to-email.php
Last active
November 4, 2020 14:54
-
-
Save andrewlimaza/e781af196ff8cf4894be9155a1cde6c5 to your computer and use it in GitHub Desktop.
PMPro add custom fields to email
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 | |
/** | |
* 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