The gform_enable_credit_card_field filter in Gravity Forms PHP enables or disables the built-in credit card field.
Usage
add_filter('gform_enable_credit_card_field', 'enable_creditcard', 11); function enable_creditcard($is_enabled) { // your custom code here return $is_enabled; }
Parameters
$is_enabled (bool)
: Value to be filtered. Usetrue
to enable the credit card field, andfalse
to disable it.
More information
See Gravity Forms Docs: gform_enable_credit_card_field
Examples
Enable Credit Card Field for All Forms
Enable the credit card field for all forms. Add the field to the form in the Form Editor.
add_filter('gform_enable_credit_card_field', 'enable_creditcard', 11); function enable_creditcard($is_enabled) { return true; }
Disable Credit Card Field for All Forms
Disable the credit card field for all forms.
add_filter('gform_enable_credit_card_field', 'disable_creditcard', 11); function disable_creditcard($is_enabled) { return false; }
Enable Credit Card Field for Specific Form
Enable the credit card field only for a specific form with form ID 2.
add_filter('gform_enable_credit_card_field', 'enable_creditcard_for_form', 11, 2); function enable_creditcard_for_form($is_enabled, $form) { if ($form['id'] == 2) { return true; } return $is_enabled; }
Disable Credit Card Field for Specific Form
Disable the credit card field only for a specific form with form ID 3.
add_filter('gform_enable_credit_card_field', 'disable_creditcard_for_form', 11, 2); function disable_creditcard_for_form($is_enabled, $form) { if ($form['id'] == 3) { return false; } return $is_enabled; }
Conditionally Enable or Disable Credit Card Field
Enable the credit card field for form ID 4, and disable it for form ID 5.
add_filter('gform_enable_credit_card_field', 'conditionally_enable_creditcard', 11, 2); function conditionally_enable_creditcard($is_enabled, $form) { if ($form['id'] == 4) { return true; } elseif ($form['id'] == 5) { return false; } return $is_enabled; }