Using Gravity Forms ‘gform_card_number’ PHP filter

The gform_card_number filter allows you to modify the “Card Number” label when creating the credit card field in a Gravity Forms form.

Usage

add_filter('gform_card_number', 'change_number', 10, 2);

Parameters

  • $label (string) – The label to be filtered.
  • $form_id (integer) – The current form’s ID.

More information

See Gravity Forms Docs: gform_card_number

Examples

Change the Card Number label

This example changes the default “Card Number” label to “Number”:

add_filter('gform_card_number', 'change_number', 10, 2);

function change_number($label, $form_id) {
    return "Number";
}

Add a prefix to the Card Number label

This example adds a prefix “Payment – ” to the Card Number label:

add_filter('gform_card_number', 'add_prefix', 10, 2);

function add_prefix($label, $form_id) {
    return "Payment - " . $label;
}

Change the Card Number label for a specific form

This example changes the Card Number label only for the form with ID 3:

add_filter('gform_card_number', 'change_number_for_form', 10, 2);

function change_number_for_form($label, $form_id) {
    if ($form_id == 3) {
        return "Credit Card Number";
    }
    return $label;
}

Add a suffix to the Card Number label

This example adds a suffix ” (Required)” to the Card Number label:

add_filter('gform_card_number', 'add_suffix', 10, 2);

function add_suffix($label, $form_id) {
    return $label . " (Required)";
}

Translate the Card Number label

This example translates the Card Number label to Spanish:

add_filter('gform_card_number', 'translate_label', 10, 2);

function translate_label($label, $form_id) {
    return "Número de Tarjeta";
}