The gform_post_payment_transaction action event is triggered after a payment transaction is created within Gravity Forms.
Usage
add_action('gform_post_payment_transaction', 'my_custom_function', 10, 6);
Parameters
- $txn_id (integer): The transaction ID associated with the payment.
- $entry_id (integer): The ID of the entry that was created.
- $transaction_type (string): The type of transaction that was made.
- $transaction_id (integer): The transaction ID of the newly created transaction.
- $amount (string): The total amount of the payment.
- $is_recurring (bool): Returns true if recurring, otherwise false.
More information
See Gravity Forms Docs: gform_post_payment_transaction
Examples
Send a custom email after a successful payment
Send an email to the site admin with the payment details after a successful payment transaction.
function send_custom_email_after_payment($txn_id, $entry_id, $transaction_type, $transaction_id, $amount, $is_recurring) { // Retrieve the entry $entry = GFAPI::get_entry($entry_id); // Get the site admin email $admin_email = get_option('admin_email'); // Prepare email subject and message $subject = 'New Payment Received'; $message = "A new payment transaction has been processed:\n"; $message .= "Entry ID: {$entry_id}\n"; $message .= "Transaction ID: {$transaction_id}\n"; $message .= "Transaction Type: {$transaction_type}\n"; $message .= "Amount: {$amount}\n"; $message .= "Recurring: " . ($is_recurring ? 'Yes' : 'No'); // Send the email wp_mail($admin_email, $subject, $message); } add_action('gform_post_payment_transaction', 'send_custom_email_after_payment', 10, 6);
Add a note to the entry after a successful payment
Add a note with the transaction details to the entry after a successful payment transaction.
function add_note_after_payment($txn_id, $entry_id, $transaction_type, $transaction_id, $amount, $is_recurring) { // Prepare the note content $note_content = "Payment transaction processed:\n"; $note_content .= "Transaction ID: {$transaction_id}\n"; $note_content .= "Transaction Type: {$transaction_type}\n"; $note_content .= "Amount: {$amount}\n"; $note_content .= "Recurring: " . ($is_recurring ? 'Yes' : 'No'); // Add the note to the entry GFFormsModel::add_note($entry_id, '0', '0', $note_content); } add_action('gform_post_payment_transaction', 'add_note_after_payment', 10, 6);