Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add last payment date and next payment date to the members list and export CSV in Paid Memberships Pro (PMPro)
/*
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