Add A New Column To The Admin Memberships Table

Note: This is part of the developer docs and is considered custom code.
Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.

If you need assistance with this, please reach out to our list of consultants for further assistance:
https://codeable.io/developers/restrict-content-pro/
If you’ve added some custom membership meta you may want to add a new column to the admin Memberships table to display that value. This can be done in two steps:

Register your new column name.
Display the column value for each membership.

This tutorial will walk you through these two steps using some custom membership meta for “Company”. 
1. Register The Column Name
This adds the column to the table, just without any values. For this we use the rcp_memberships_list_table_columns filter.
function ag_rcp_memberships_list_table_columns( $columns ) {

$key = ‘company’; // All lowercase, no spaces. Your unique ID for your column.
$name = __( ‘Company’, ‘rcp’ ); // Label to be displayed on the column header. Spaces are okay.

$columns[ $key ] = $name;

return $columns;

}
add_filter( ‘rcp_memberships_list_table_columns’, ‘ag_rcp_memberships_list_table_columns’ );

The $key value needs to be changed. This should be all lowercase and use underscores instead of spaces (or no spaces).
The $name value needs to be changed. This is the label that is displayed in the column header. Spaces are okay here.
Once configured, the column will appear on the table, like so:

2. Display The Column Value
The next step is to populate the column value for each membership record. For this we use the rcp_memberships_list_table_column_{column} filter.
function ag_rcp_memberships_list_table_column_company( $value, $membership ) {

$company = rcp_get_membership_meta( $membership->get_id(), ‘company’, true );

return $company;

}
add_filter( ‘rcp_memberships_list_table_column_company’, ‘ag_rcp_memberships_list_table_column_company’, 10, 2 );

Make sure you edit the rcp_memberships_list_table_column_company filter to match your column key that you set in step 1. The correct filter to use is rcp_memberships_list_table_column_{column_key} where {column_key} is the key you chose. In my case that’s company, which is why my filter name is rcp_memberships_list_table_column_company.
Inside the function, we use the membership meta API to retrieve our desired value. You will need to edit this to return your desired value. In this example, we retrieve the membership meta ‘company’.
In the end, the table looks like this:

3. Remove Default Columns
You can also use the rcp_memberships_list_table_columns filter to remove default columns. All you need to know is the key to the column you want to remove. The default keys are as follows:

customer – Customer column
object_id – Membership level name column
status – Status column
auto_renew – Recurring column
created_date – Created column
expiration_date – Expiration date column

For example, this code can be used to remove the created date column:
function ag_rcp_memberships_list_remove_column( $columns ) {
$key_to_remove = ‘created_date’; // Change this to the key you want to remove.

if ( array_key_exists( $key_to_remove, $columns ) ) {
unset( $columns[ $key_to_remove] );
}

return $columns;
}
add_filter( ‘rcp_memberships_list_table_columns’, ‘ag_rcp_memberships_list_remove_column’ );
Please note: All of these examples serve as a guideline and are here for your convenience. We do not provide support for troubleshooting or modifying these and we do not provide support for any custom development. If you need help with any of these examples, consider hiring a developer.

Have more questions?

Submit a request