gform_format_option_label

Description

This filter is executed when calculating and displaying the pricing on product option fields or shipping fields set as drop down field or radio buttons type. Use this filter to change the format of the choice labels for these field types.

Usage

<script type="text/javascript">

//Simply implement the function with name "gform_format_option_label" to activate the javascript filter. The value returned by this function will be used as the option label.

function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId){

      //disabling option pricing. simply return the field label.
      return fieldLabel;
}

</script>

Parameters

  • fullLabel string

    The default label that will be displayed for the current option. It has the field choice label as well as the calculated price. (i.e. My Option +$5.00)

  • fieldLabel string

    The field/option label without the price. (i.e. My Option)

  • priceLabel string

    The price text without the field label. (i.e. +$5.00)

  • selectedPrice float

    The price of the currently selected option.

  • price float

    The price of this option. (The option that this label applies to)

  • formId integer

    The current form ID.

  • fieldId integer

    The current field ID.

Examples

Remove Price from Label

The following example disables the option pricing, displaying only the option label.

<script type="text/javascript">

    function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId){

          //disabling option pricing. simply return the field label.
          return fieldLabel;
    }

</script>

Display Price before Label

The following example changes the order of the labels, displaying the option price before the field label. I only does that for form ID 5.

<script type="text/javascript">

function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId){

    //ignore all forms, except the one with ID = 5
    if(formId != 5)
      return fullLabel;

    //ignore all fields except the one with ID = 10
    if(fieldId != 10)
     return fullLabel;

    //changing label
    return priceLabel + " " + fieldLabel;
}

</script>

Show Option Price instead of Variable Pricing

This example replaces the variable pricing with the static full option price for a field with id 43.

<script type="text/javascript">

function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId) {
    if ( fieldId != 43 ) { // Change 43 to your field id number.
        return fullLabel;
    }
    priceLabel = " <span class='ginput_price'>" + gformFormatMoney(price) + '</span>';
    return fieldLabel + priceLabel;
}

</script>

Placement

This code should be placed in an HTML field on your form or you may use the gform_pre_render hook to echo the script block to the page.

Source Code

This filter is located in gravityforms.js