Description
Use this filter to change the default list of supported credit card types.
Important: The Credit Card field is deprecated. If you are currently using an add-on that relies on it, such as Authorize.net, PayPal Pro, or PayPal Payments Pro, we strongly recommend transitioning to an alternative payment add-on. Consider using Stripe, PayPal Checkout, Square, or Mollie, and utilize the respective fields provided with these add-ons.
Usage
add_filter( 'gform_creditcard_types', 'add_card_type' );
Parameters
- $cards array
The card array to be filtered. It is defined as follows:
$cards = array(
array(
'name' => 'American Express',
'slug' => 'amex',
'lengths' => '15',
'prefixes' => '34,37',
'checksum' => true
),
array(
'name' => 'Discover',
'slug' => 'discover',
'lengths' => '16',
'prefixes' => '6011,622,64,65',
'checksum' => true
),
array(
'name' => 'MasterCard',
'slug' => 'mastercard',
'lengths' => '16',
'prefixes' => '51,52,53,54,55',
'checksum' => true
),
array(
'name' => 'Visa',
'slug' => 'visa',
'lengths' => '13,16',
'prefixes' => '4,417500,4917,4913,4508,4844',
'checksum' => true
),
array(
'name' => 'JCB',
'slug' => 'jcb',
'lengths' => '16',
'prefixes' => '35',
'checksum' => true
),
array(
'name' => 'Maestro',
'slug' => 'maestro',
'lengths' => '12,13,14,15,16,18,19',
'prefixes' => '5018,5020,5038,6304,6759,6761',
'checksum' => true
)
);
Note: The lengths, prefixes and checksum properties are used for validation and card type detection. Lengths indicates the card number’s allowed number of digits, prefixes indicates the allowed starting digit sequence and checksum indicates if the card validation requires a checksum.
Examples
This example removes Maestro from the list of available credit cards.
add_filter( 'gform_creditcard_types', 'remove_maestro' );
function remove_maestro( $cards ) {
unset( $cards[5] ); // removing Maestro from the list
return $cards;
}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::get_card_types() in common.php.