Using Gravity Forms ‘gform_creditcard_types’ PHP action

The gform_creditcard_types Gravity Forms filter allows you to modify the default list of supported credit card types.

Usage

add_filter('gform_creditcard_types', 'add_card_type');

Parameters

  • $cards (array) – The card array to be filtered. It contains information about each credit card type, such as name, slug, lengths, prefixes, and whether a checksum is required for validation.

More information

See Gravity Forms Docs: gform_creditcard_types

Examples

Remove Maestro from supported credit cards

This example removes Maestro from the list of available credit cards.

add_filter('gform_creditcard_types', 'remove_maestro');

function remove_maestro($cards) {
    unset($cards[array_search('maestro', array_column($cards, 'slug'))]);
    return $cards;
}

Add a custom credit card type

This example adds a custom credit card type called “BankCard” to the list of supported credit cards.

add_filter('gform_creditcard_types', 'add_bankcard');

function add_bankcard($cards) {
    $cards[] = array(
        'name' => 'BankCard',
        'slug' => 'bankcard',
        'lengths' => '16',
        'prefixes' => '56',
        'checksum' => true
    );
    return $cards;
}

Change the display name of a credit card type

This example changes the display name of the Visa credit card type to “Visa Card”.

add_filter('gform_creditcard_types', 'change_visa_name');

function change_visa_name($cards) {
    $index = array_search('visa', array_column($cards, 'slug'));
    $cards[$index]['name'] = 'Visa Card';
    return $cards;
}

Remove credit card types based on their length

This example removes all credit card types with a length of 16 digits from the list of supported credit cards.

add_filter('gform_creditcard_types', 'remove_length_16_cards');

function remove_length_16_cards($cards) {
    foreach ($cards as $key => $card) {
        if (strpos($card['lengths'], '16') !== false) {
            unset($cards[$key]);
        }
    }
    return $cards;
}

Change the supported card number prefixes for a credit card type

This example changes the supported card number prefixes for the MasterCard credit card type.

add_filter('gform_creditcard_types', 'change_mastercard_prefixes');

function change_mastercard_prefixes($cards) {
    $index = array_search('mastercard', array_column($cards, 'slug'));
    $cards[$index]['prefixes'] = '51,52,53,54,55,2221-2720';
    return $cards;
}