The gform_action_pre_payment_callback action in Gravity Forms runs a custom function after a payment has been made but before the callback function is triggered.
Usage
To use this action, you would typically add it to your custom function in your theme’s functions.php
file, like so:
add_action( 'gform_action_pre_payment_callback', 'my_custom_function', 10, 2 ); function my_custom_function($action, $entry) { // your custom code here return $action; }
Parameters
- $action (array): This is the array for the payment action that has been triggered.
- $entry (Entry Object): This represents the new entry that has been created.
More information
For more detailed information, see the Gravity Forms Docs: gform_action_pre_payment_callback
This action hook is located in GFPaymentAddOn::process_callback_action()
in the file includes/addon/class-gf-payment-addon.php
.
Examples
Send an email when payment is complete
You can use this action to send a custom email when a payment is complete.
add_action( 'gform_action_pre_payment_callback', 'send_email_on_complete_payment', 10, 2 ); function send_email_on_complete_payment($action, $entry) { if( $action['type'] == 'complete_payment' ) { wp_mail('[email protected]', 'Payment Completed', 'Payment has been completed.'); } }
In this example, the function checks if the payment is complete. If it is, it sends an email.
Update a user meta when payment is complete
This action could be used to update a user meta when a payment is complete.
add_action( 'gform_action_pre_payment_callback', 'update_user_meta_on_complete_payment', 10, 2 ); function update_user_meta_on_complete_payment($action, $entry) { if( $action['type'] == 'complete_payment' ) { $user_id = get_current_user_id(); update_user_meta($user_id, 'payment_status', 'completed'); } }
This function updates the ‘payment_status’ meta for the current user when the payment is complete.
Log payment actions
You can use this action to log payment actions for debugging or record keeping.
add_action( 'gform_action_pre_payment_callback', 'log_payment_actions', 10, 2 ); function log_payment_actions($action, $entry) { error_log(print_r($action, true)); }
In this example, the function logs the action data for each payment action.
Run a custom function based on payment amount
This action could be used to trigger different functions based on the payment amount.
add_action( 'gform_action_pre_payment_callback', 'custom_function_based_on_amount', 10, 2 ); function custom_function_based_on_amount($action, $entry) { if( $action['amount'] > 100 ) { // Run your custom function for payments over $100 } }
In this example, the function checks the payment amount and runs a custom function for payments over $100.