The gform_authorizenet_amount_pre_authorize filter allows you to modify the authorization amount before it is sent to Authorize.net.
Usage
To use this filter, add it to your theme’s functions.php file:
add_filter('gform_authorizenet_amount_pre_authorize', 'your_function_name', 10, 6);
Parameters
- $auth_amount (float): The authorization amount. Defaults to the value of
$config['amount']. - $transaction (object): The Authorize.net transaction object.
- $form_data (array): An associative array containing the form title, billing address, payment amount, setup fee amount, line items created using the submitted pricing field values, and any discounts from coupons.
- $config (array): The feed currently being processed.
- $form (array): The form currently being processed.
- $entry (array): The entry currently being processed. (Available since version 2.1.8).
More information
See Gravity Forms Docs: gform_authorizenet_amount_pre_authorize
Examples
Override the authorization amount for a specific form
This example shows how to override the authorization amount for a specific form with ID 10:
add_filter('gform_authorizenet_amount_pre_authorize', 'change_amount', 10, 6);
function change_amount($auth_amount, $transaction, $form_data, $config, $form, $entry) {
if ($form['id'] == 10) {
$auth_amount = 1;
}
return $auth_amount;
}
Apply a discount to the authorization amount
This example shows how to apply a 10% discount to the authorization amount for a specific form with ID 20:
add_filter('gform_authorizenet_amount_pre_authorize', 'apply_discount', 10, 6);
function apply_discount($auth_amount, $transaction, $form_data, $config, $form, $entry) {
if ($form['id'] == 20) {
$auth_amount *= 0.9;
}
return $auth_amount;
}
Set a minimum authorization amount
This example sets a minimum authorization amount of $5 for all forms:
add_filter('gform_authorizenet_amount_pre_authorize', 'set_minimum_amount', 10, 6);
function set_minimum_amount($auth_amount, $transaction, $form_data, $config, $form, $entry) {
if ($auth_amount < 5) {
$auth_amount = 5;
}
return $auth_amount;
}
Increase the authorization amount based on a custom field
This example increases the authorization amount by the value of a custom field with ID 5:
add_filter('gform_authorizenet_amount_pre_authorize', 'increase_amount_based_on_custom_field', 10, 6);
function increase_amount_based_on_custom_field($auth_amount, $transaction, $form_data, $config, $form, $entry) {
$custom_field_value = rgar($entry, '5');
$auth_amount += $custom_field_value;
return $auth_amount;
}
Apply a membership discount
This example applies a membership discount of 15% to the authorization amount for members:
add_filter('gform_authorizenet_amount_pre_authorize', 'apply_membership_discount', 10, 6);
function apply_membership_discount($auth_amount, $transaction, $form_data, $config, $form, $entry) {
// Check if the user is a member (replace this with your own membership check)
$is_member = check_user_membership();
if ($is_member) {
$auth_amount *= 0.85;
}
return $auth_amount;
}
// Replace this function with your own membership check logic
function check_user_membership() {
// Example: return true if user is a member, false otherwise
return true;
}
These examples demonstrate various ways to use the gform_authorizenet_amount_pre_authorize filter to modify the authorization amount before it is sent to Authorize.net. Remember to replace `your_function_name` with an appropriate function name and adapt the code to your specific requirements.