Using Gravity Forms ‘gform_stripe_object’ PHP filter

The gform_stripe_object Gravity Forms PHP filter allows you to modify the arguments used when creating a Stripe object.

Usage

add_filter('gform_stripe_object', 'your_function_name', 10, 2);

Parameters

  • $args (array): An array of the various arguments used to create the Stripe object.
  • $form_id (int): The ID of the form.

More information

See Gravity Forms Docs: gform_stripe_object

Examples

Set Custom Credit Card Field ID

Change the credit card field ID in the Stripe object to 8.

add_filter('gform_stripe_object', 'set_stripe_args', 10, 2);
function set_stripe_args($args, $form_id) {
    $args['ccFieldId'] = 8;
    return $args;
}

Set Stripe Currency

Change the Stripe currency to ‘EUR’ for a specific form with ID 5.

add_filter('gform_stripe_object', 'set_stripe_currency', 10, 2);
function set_stripe_currency($args, $form_id) {
    if ($form_id == 5) {
        $args['currency'] = 'EUR';
    }
    return $args;
}

Set Custom Stripe API Key

Use a custom Stripe API key for a specific form with ID 7.

add_filter('gform_stripe_object', 'set_custom_api_key', 10, 2);
function set_custom_api_key($args, $form_id) {
    if ($form_id == 7) {
        $args['apiKey'] = 'your_custom_api_key_here';
    }
    return $args;
}

Enable Stripe Billing Address

Enable the billing address collection for a specific form with ID 3.

add_filter('gform_stripe_object', 'enable_billing_address', 10, 2);
function enable_billing_address($args, $form_id) {
    if ($form_id == 3) {
        $args['billing_info'] = true;
    }
    return $args;
}

Disable Stripe Metadata

Disable metadata collection for a specific form with ID 12.

add_filter('gform_stripe_object', 'disable_stripe_metadata', 10, 2);
function disable_stripe_metadata($args, $form_id) {
    if ($form_id == 12) {
        $args['metadata'] = false;
    }
    return $args;
}