Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dwanjuki/7023c1e5394bd79e5e6a894a3047e41d to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/7023c1e5394bd79e5e6a894a3047e41d to your computer and use it in GitHub Desktop.
Adds last payment date to the members list and export CSV in Paid Memberships Pro (PMPro).
<?php
/**
* Adds last payment date to the members list and export CSV.
*
* 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/
*/
// Adds "Last Payment" column to Members List.
function my_pmpro_add_memberslist_col_last_payment_date( $columns ) {
$columns[ 'last-payment' ] = 'Last Payment';
return $columns;
}
add_filter( 'pmpro_manage_memberslist_columns', 'my_pmpro_add_memberslist_col_last_payment_date' );
// Fills the "last-payment" column of the Members List.
function my_pmpro_fill_memberslist_col_last_payment_date( $colname, $user_id ) {
if ( 'last-payment' === $colname ) {
$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';
}
}
}
add_filter( 'pmpro_manage_memberslist_custom_column', 'my_pmpro_fill_memberslist_col_last_payment_date', 10, 2 );
// Adds "Last Payment" column to Members List CSV export.
function my_pmpro_members_list_csv_extra_columns_last_payment_date( $columns ) {
$columns[ 'last_payment' ] = 'my_extra_column_last_payment';
return $columns;
}
add_filter( 'pmpro_members_list_csv_extra_columns', 'my_pmpro_members_list_csv_extra_columns_last_payment_date', 10);
// Populate the "last_payment" column of the Members List CSV export.
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 '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment