Home / Archive / MemberPress: Add a Custom Field To Manage Sub Account Table
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add a Custom Field To Manage Sub Account Table

This shortcode can be used if the MemberPress Corporate Accounts add-on is activated on the website.

The code adds a column to the sub account table under your users’ Account > Subscription > Sub-Accounts page. This column will display a custom field for sub account users.

Custom fields can be created at Dashboard > MemberPress >Settings > Fields.

To add the created custom field to the Sub-Accounts page, the following line should be edited:

On this line, the Custom Field text should be changed to the text that should be displayed as the custom field label on the sub account page.

Next, the memberpress-corporate should be changed to match the custom field name. The text should be entirely in lowercase, and any spaces in the name should be replaced with a dash (-).

Finally, the mepr_company_name dummy slug should be replaced by the slug of the custom field. The custom field slug is available at Dashboard > MemberPress >Settings > Fields.

Code Preview
php
<?php
add_action( 'mpca-sub-accounts-th', function( $curr_user, $sub_accounts ) { ?>
  <th><?php _ex( 'Custom Field', 'ui', 'memberpress-corporate' ); ?></th>
<?php }, 10, 2);
add_action( 'mpca-sub-accounts-td', function( $curr_user, $sub_account ) {
  $cf = get_user_meta( ( int ) $sub_account->ID, 'mepr_company_name', true );
  ?>
  <td><?php echo $cf; ?></td>
<?php }, 10, 2 );

Comments

Add a Comment