The gform_paypal_invoice filter allows you to modify the invoice number sent to PayPal for the PayPal Standard Add-on.
Usage
add_filter('gform_paypal_invoice', 'your_function_name', 10, 3);
Parameters
- $invoice_id (integer): Empty string.
- $form (Form Object): The form from which the PayPal transaction was submitted.
- $entry (Entry Object): The entry used to generate the PayPal transaction.
More information
See Gravity Forms Docs: gform_paypal_invoice
Examples
Use Entry ID as Invoice ID
This example sets the invoice ID to the entry ID.
add_filter('gform_paypal_invoice', 'change_invoice', 10, 3); function change_invoice($invoice_id, $form, $entry) { return rgar($entry, 'id'); }
Append Prefix to Invoice ID
This example appends a custom prefix to the invoice ID.
add_filter('gform_paypal_invoice', 'append_invoice_prefix', 10, 3); function append_invoice_prefix($invoice_id, $form, $entry) { $prefix = 'INV-'; return $prefix . rgar($entry, 'id'); }
Add Form ID to Invoice ID
This example adds the form ID to the invoice ID.
add_filter('gform_paypal_invoice', 'add_form_id_to_invoice', 10, 3); function add_form_id_to_invoice($invoice_id, $form, $entry) { return rgar($entry, 'id') . '-' . rgar($form, 'id'); }
Generate Random Invoice ID
This example generates a random invoice ID using a combination of entry ID and a random number.
add_filter('gform_paypal_invoice', 'generate_random_invoice_id', 10, 3); function generate_random_invoice_id($invoice_id, $form, $entry) { $random_number = mt_rand(1000, 9999); return rgar($entry, 'id') . '-' . $random_number; }
Use Entry Date as Invoice ID
This example sets the invoice ID to the entry’s submission date.
add_filter('gform_paypal_invoice', 'set_entry_date_as_invoice_id', 10, 3); function set_entry_date_as_invoice_id($invoice_id, $form, $entry) { return str_replace('-', '', rgar($entry, 'date_created')); }