Using Gravity Forms ‘gform_stripe_payment_element_payment_methods’ PHP filter

The gform_stripe_payment_element_payment_methods filter allows you to manually set the payment methods displayed in the Stripe Payment Element.

Usage

add_filter('gform_stripe_payment_element_payment_methods', function($payment_methods, $feed, $form) {
    // your custom code here
    return $payment_methods;
}, 10, 3);

Parameters

  • $payment_methods (array): An array of payment methods to be used.
  • $feed (array): The feed currently being processed.
  • $form (array): The form which created the current entry.

More information

See Gravity Forms Docs: gform_stripe_payment_element_payment_methods

Place this code in the functions.php file of the active theme, a custom functions plugin, or a custom add-on.

Examples

Display Card, US Bank Account, and iDEAL payment methods

This example shows how to display the Card, US Bank Account, and iDEAL payment methods.

add_filter('gform_stripe_payment_element_payment_methods', function($payment_methods, $feed, $form) {
    return array('card', 'us_bank_account', 'ideal');
}, 10, 3);

Display Card and SOFORT payment methods for a specific form

This example shows how to display the Card and SOFORT payment methods for a specific form with an ID of 5.

add_filter('gform_stripe_payment_element_payment_methods', function($payment_methods, $feed, $form) {
    if ($form['id'] == 5) {
        return array('card', 'sofort');
    }
    return $payment_methods;
}, 10, 3);

Display SEPA Debit payment method based on form field value

This example shows how to display the SEPA Debit payment method if a specific form field has a value of “SEPA”.

add_filter('gform_stripe_payment_element_payment_methods', function($payment_methods, $feed, $form) {
    $field_value = rgpost('input_10'); // Replace 10 with the field ID
    if ($field_value == 'SEPA') {
        return array('card', 'sepa_debit');
    }
    return $payment_methods;
}, 10, 3);

Display additional payment methods based on user role

This example shows how to display additional payment methods for users with a specific role.

add_filter('gform_stripe_payment_element_payment_methods', function($payment_methods, $feed, $form) {
    if (current_user_can('vip_user')) { // Replace 'vip_user' with the desired role
        return array('card', 'us_bank_account', 'ideal', 'sofort', 'link');
    }
    return $payment_methods;
}, 10, 3);

Display only Card payment method for a specific feed

This example shows how to display only the Card payment method for a specific feed with an ID of 15.

add_filter('gform_stripe_payment_element_payment_methods', function($payment_methods, $feed, $form) {
    if ($feed['id'] == 15) {
        return array('card');
    }
    return $payment_methods;
}, 10, 3);