Pre-generate Invoices for Manual Payments

By default, Invoices are only generated after a payment is completed. For manual payments, this can be changed so the invoice gets generated at the moment that the user requests the new payment.
The user can then use the invoice number in the details field so the admin has an easier time to identify and confirm the payment.

After adding the code from below to your website, when an user initiates a manual payment (by registering on your website, renewal for a subscription, upgrade etc.) he will be able to download the Invoice immediately from the [pms-payment-history] shortcode. The Invoice will be available for admins in the back-end as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
add_filter('pms_inv_is_invoice_allowed', 'pmsc_pregenerate_invoice_for_manual_payments', 20, 2);
function pmsc_pregenerate_invoice_for_manual_payments($return, $payment_id) {
    if (empty($payment_id))
        return false;
 
    $payment = pms_get_payment($payment_id);
 
    if ($payment->payment_gateway != 'manual')
        return $return;
 
    $settings = get_option( 'pms_invoices_settings', array() );
 
    if(empty($settings['company_details']))
        return false;
 
    pms_inv_payment_complete_generate_invoice_number( $payment_id, array('status' => 'completed') );
 
    $invoice_number = pms_get_payment_meta( $payment_id, 'pms_inv_invoice_number', true );
 
    if( empty( $invoice_number ) )
        return false;
 
    return true;
}
For this to work correctly you will need:

  • Paid Member Subscriptions – version 1.6.4 or higher
  • Invoices add-on – version 1.0.1 or higher