Skip to content

Instantly share code, notes, and snippets.

@JarrydLong
Last active December 20, 2024 13:58
Show Gist options
  • Select an option

  • Save JarrydLong/b663e5aad0cf05425b57c5d5241700f0 to your computer and use it in GitHub Desktop.

Select an option

Save JarrydLong/b663e5aad0cf05425b57c5d5241700f0 to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe adds a !!next_payment_date!! variable to your email templates.
* Note that this will only work with recurring levels and not for levels that expire or are once off.
*
* 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 mypmpro_next_payment_date_email_var( $email_data,$email ){
if( ! function_exists( 'pmpro_next_payment' ) ) {
return $email_data;
}
$user = get_user_by( 'email', $email_data['user_email'] );
if( ! $user ) {
return $email_data;
}
//Get next payment date
$next_payment_date = pmpro_next_payment( $user->ID );
if( ! $next_payment_date ) {
return $email_data;
}
$email_data['next_payment_date'] = date( get_option( 'date_format' ), $next_payment_date );
return $email_data;
}
add_filter( 'pmpro_email_data', 'mypmpro_next_payment_date_email_var', 10, 2 );
@dwanjuki
Copy link

The snippet returns the date of the current payment in the Recurring Payment Receipt email. Reason, the subscription details are updated after that email has been sent out.

Here's a variation that gives the expected next payment date in that template, calculates date from the level & order details: https://gist.github.com/dwanjuki/d9a1fb83101af2f91e7ec3d9e59a899e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment