Modifying Price Product Price for a SINGLE field via gform_product_price

I have a form that uses several product fields. I need to modify ONE of the product fields.

I can target the individual form, but the gform_product_price filter (reference) changes ALL of the product fields. Is there any way to target just ONE?

Please Advise

Thanks

Hi Preston. The filter applies to all the product fields in one form, if you target it by form. It does not apply to individual products in that form. If you have any other questions, please let us know.

Looking at the code on this one, it appears that you might be able to also call up a third argument (field ID) into that filter. With that, youā€™d be able to conditionally check/apply based on that field ID. However, it looks like that third parameter is not available when the filter is run on the entry detail screen. Maybe try something like this? Iā€™ve not tested ā€“ only guessing from what I see in the filter. Curious to know what you find.

add_filter( 'gform_product_price_185', 'set_price_label', 10, 3 );
function set_price_label( $sublabel, $form_id, $field_id ) {
  if ( $field_id == 3 ) {
    return 'Cost';
  }
}
1 Like

Greetings Joshua,

Nice shot, code-wise. Unfortunately, it did not work for me. Generated a fatal error.

Thanks!

-pd

It would be nice if we could target just one or all fields.

ā€¦just saying (hint, hint).

Ah, probably also need to add an else statement.

add_filter( 'gform_product_price_185', 'set_price_label', 10, 3 );
function set_price_label( $sublabel, $form_id, $field_id ) {
  if ( $field_id == 3 ) {
    return 'Cost';
  } else {
    return $sublabel;
  }
}

Nope. Does not generate an error, but fails at returning ā€˜Costā€™. Reverts back to (else) displaying ā€œPriceā€. ā€¦and I also double-checked that I am referencing the correct field.

Did you also change the _185 so as to apply to the proper form?

Yes Sir, I did. Iā€™d be curious to know if you ever do test it. Hope this is not just me :blush:

1 Like

@Preston - if you want to suggest this change, I recommend adding a note for our product team here. https://www.gravityforms.com/gravity-forms-roadmap/ - Click the blue :heavy_plus_sign: in the lower left on this page to add a note for our product team:

Thank you.

Done. Thanks!

2 Likes

This worked for me. In this example 21 is the form number and 24 is the field to be targeted/changed:

//change 'Price' label to 'Credit Card Surcharge'
add_filter( 'gform_product_price_21_24', 'set_price_label', 10, 2 );
function set_price_label( $sublabel, $form_id ) {
    return 'Credit Card Surcharge';
}
1 Like