Last active
February 21, 2022 15:37
-
-
Save ideadude/15c1a55d6ec920ae6ec5f7ab47e1a232 to your computer and use it in GitHub Desktop.
PMPro: Show the next payment date instead of the expiration date for the !!membership_expiration!! email var if it's blank.
This file contains hidden or 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 | |
/** | |
* Show the next payment date instead of the expiration date | |
* for the !!membership_expiration!! email var if it's blank. | |
* Add this code into a custom plugin or Code Snippet. | |
* More information on how to add code snippets here: https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/ | |
*/ | |
function my_email_var_membership_expiration( $data, $email ) { | |
if ( empty( $data['membership_expiration'] ) ) { | |
$user = get_user_by( 'email', $data['user_email'] ); | |
if ( ! empty( $user ) ) { | |
// We want to ping the gateways when we check for the next payment date. | |
add_filter('pmpro_next_payment', array('PMProGateway_paypalexpress', 'pmpro_next_payment'), 10, 3); | |
add_filter('pmpro_next_payment', array('PMProGateway_stripe', 'pmpro_next_payment'), 10, 3); | |
$next_payment = pmpro_next_payment( $user->ID ); | |
if ( ! empty( $next_payment ) ) { | |
$data['membership_expiration'] = '<p>Your next payment will be on ' . date_i18n( get_option( 'date_format' ), $next_payment ) . '.</p>'; | |
} | |
} | |
} | |
return $data; | |
} | |
add_filter( 'pmpro_email_data', 'my_email_var_membership_expiration', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment