Home / Archive / MemberPress: Adding Credit Card and Expiry Information to Subscriptions Table
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Adding Credit Card and Expiry Information to Subscriptions Table

This snippet adds a new column to the table under the Subscriptions tab on the Account page. This new column displays the last four digits of the user's credit card and its expiration date.

Code Preview
php
<?php
// Add the "Card/Expiry" column header
function mepr_add_subscriptions_th($user, $subs) {
  ?>
    <th>Card/Expiry</th>
  <?php
}
add_action('mepr-account-subscriptions-th', 'mepr_add_subscriptions_th', 10, 2);
// Add the credit card details in the table row
function mepr_add_subscriptions_td($user, $sub, $txn, $is_recurring) {
	$sub_obj = new MeprSubscription($sub->id);
  ?>
    <td data-label="Card/Expiry">
	  <?php if ($sub_obj->cc_last4) { ?>
		  <p class="card"><?php echo '**** '. esc_html($sub_obj->cc_last4); ?></p>
		  <p class="month_year"><?php echo esc_html($sub_obj->cc_exp_month . '/' . $sub_obj->cc_exp_year); ?></p>
	  <?php } ?>
    </td>
  <?php
}
add_action('mepr-account-subscriptions-td', 'mepr_add_subscriptions_td', 10, 4);

Comments

Add a Comment