Using Gravity Forms ‘gform_post_payment_refunded’ PHP filter

The gform_post_payment_refunded Gravity Forms action is triggered after a payment is refunded, allowing you to take additional actions.

Usage

add_action('gform_post_payment_refunded', 'my_function', 10, 2);

Parameters

  • $entry (Entry Object) – The entry object that was created.
  • $action (array) – The action that occurred. Contains information such as the amount, what occurred, and the transaction ID.

More information

See Gravity Forms Docs: gform_post_payment_refunded

This action hook is located in GFPaymentAddOn::refund_payment() in includes/addon/class-gf-payment-addon.php.

Examples

Send an email when a payment is refunded

Send a notification email to the site administrator when a payment is refunded.

function send_refund_email($entry, $action) {
    // Get admin email
    $admin_email = get_option('admin_email');

    // Prepare email subject and body
    $subject = "Payment Refunded";
    $body = "A payment has been refunded.\n\n";
    $body .= "Entry ID: {$entry['id']}\n";
    $body .= "Transaction ID: {$action['transaction_id']}\n";
    $body .= "Refund Amount: {$action['amount']}";

    // Send email
    wp_mail($admin_email, $subject, $body);
}
add_action('gform_post_payment_refunded', 'send_refund_email', 10, 2);

Add a note to the entry when a payment is refunded

Add a note to the Gravity Forms entry when a payment is refunded.

function add_refund_note($entry, $action) {
    // Create note content
    $note = "Payment Refunded: {$action['amount']}";

    // Add note to entry
    GFFormsModel::add_note($entry['id'], 'refund', 'Administrator', $note);
}
add_action('gform_post_payment_refunded', 'add_refund_note', 10, 2);

Update a custom field in the user’s profile when a payment is refunded

Update a custom field in the user’s profile with the refund amount when a payment is refunded.

function update_user_custom_field($entry, $action) {
    // Get user from entry
    $user = get_user_by('email', $entry['3']); // Replace '3' with the email field ID

    // Update custom field in user profile
    update_user_meta($user->ID, 'refund_amount', $action['amount']);
}
add_action('gform_post_payment_refunded', 'update_user_custom_field', 10, 2);

Adjust available stock when a payment is refunded

Increase the available stock of a product when a payment is refunded.

function adjust_stock_on_refund($entry, $action) {
    // Get product ID from entry
    $product_id = $entry['5']; // Replace '5' with the product field ID

    // Get current stock
    $current_stock = get_post_meta($product_id, '_stock', true);

    // Increase stock by 1
    $new_stock = $current_stock + 1;

    // Update stock
    update_post_meta($product_id, '_stock', $new_stock);
}
add_action('gform_post_payment_refunded', 'adjust_stock_on_refund', 10, 2);