Last active
August 31, 2021 21:21
-
-
Save strangerstudios/6b8277b14f4f1dc5871cca70b6ac5d98 to your computer and use it in GitHub Desktop.
Add last payment date and next payment date to the members list and export CSV in Paid Memberships Pro (PMPro)
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
/* | |
Add last paymenet date and next payment date to the members list and export CSV | |
Add this code into a custom plugin or your active theme's functions.php. | |
Note that "last payment" value will get the last order in "success", "cancelled", or "" status. | |
(Oddly enough, cancelled here means that the membership was cancelled, not the order.) | |
The "next payment" value is an estimate based on the billing cycle of the subscription and the last order date. | |
It may be off form the actual recurring date set at the gateway, especially if the subscription was updated at the gateway. | |
*/ | |
//add columns to members list | |
function my_pmpro_memberslist_extra_cols_header($theusers) | |
{ | |
?> | |
<th><?php _e('Last Payment', 'pmpro');?></th> | |
<th><?php _e('Next Payment', 'pmpro');?></th> | |
<?php | |
} | |
add_action('pmpro_memberslist_extra_cols_header', 'my_pmpro_memberslist_extra_cols_header'); | |
//add last/next payment to each row in the members list | |
function my_pmpro_memberslist_extra_cols_body($user) | |
{ | |
?> | |
<td> | |
<?php | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder($user->ID, array('success', 'cancelled', '')); | |
if(!empty($order) && !empty($order->id)) { | |
echo date(get_option('date_format'), $order->timestamp); | |
} else { | |
echo "N/A"; | |
} | |
?> | |
</td> | |
<td> | |
<?php | |
$next = pmpro_next_payment($user->ID, array('success', 'cancelled', ''), 'date_format'); | |
if($next) | |
echo $next; | |
else | |
echo "N/A"; | |
?> | |
</td> | |
<?php | |
} | |
add_action('pmpro_memberslist_extra_cols_body', 'my_pmpro_memberslist_extra_cols_body'); | |
//add csv column headings | |
function my_pmpro_members_list_csv_extra_columns($columns) | |
{ | |
$columns["last_payment"] = "my_extra_column_last_payment"; | |
$columns["next_payment"] = "my_extra_column_next_payment"; | |
return $columns; | |
} | |
add_filter("pmpro_members_list_csv_extra_columns", "my_pmpro_members_list_csv_extra_columns", 10); | |
//last_payment csv | |
function my_extra_column_last_payment($user) | |
{ | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder($user->ID, array('success', 'cancelled', '')); | |
if(!empty($order) && !empty($order->id)) { | |
return date(get_option('date_format'), $order->timestamp); | |
} else { | |
return ""; | |
} | |
} | |
//last_payment csv | |
function my_extra_column_next_payment($user) | |
{ | |
return pmpro_next_payment($user->ID, array('success', 'cancelled', ''), 'date_format'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMPORTANT NOTE: This gist is out of date.
The latest version of this gist can be found here: https://gist.github.com/kimcoleman/8fb6f167180f8d9435f08b25bfcc85bc