Home / Archive / MemberPress: Add the Invoice Number to the Transactions Screen
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add the Invoice Number to the Transactions Screen

If the MemberPress PDF Invoice add-on is activated on the website, MemberPress will start generating invoices for all MemberPress-related transactions.

This code snippet adds an additional Invoice IDs column to the transactions table at Dashboard > MemberPress > Transactions. This column shows the invoice number for each paid transaction.

Code Preview
php
<?php
add_filter('mepr-admin-transactions-cols', function ($cols) {
  $cols['col_txn_invoice'] = __('Invoice No.', 'memberpress-pdf-invoice');
  return $cols;
});
add_action('mepr-admin-transactions-cell', function ($column_name, $rec, $attributes) {
  if ($column_name === 'col_txn_invoice') {
    ?>
    <td <?php echo $attributes; ?>>
    <?php
      try {
      $mepr_options = MeprOptions::fetch();
      $text         = $mepr_options->get_attr( 'biz_invoice_format' );
      $txn          = new MeprTransaction( $rec->id );
      $params       = MePdfInvoicesHelper::get_invoice_params( $txn );
      $invoice_num  = MePdfInvoiceNumber::get_invoice_num($txn->id);
      $invoice_num_str  = MeprUtils::replace_vals( $text, $params );
      if ($invoice_num && $invoice_num_str && !empty($invoice_num_str)) {
        echo $invoice_num_str;
      }
    } catch (exception $e) {
    }
    ?>
    </td>
    <?php
  }
}, 10, 3);

Comments

Add a Comment