Description
The gform/products/get_product_meta filter can be used to modify the product metadata for a field.
Usage
gform.utils.addFilter( 'gform/products/get_product_meta', function( data ) {
// do stuff
return data;
} );
Parameters
| Parameter | Type | Description |
|---|---|---|
data | object | The data object passed to the filter. |
data.field | HTMLElement | The product, option or shipping field element. |
data.fieldId | string | The field ID. |
data.inputType | string | The field input type (e.g. text, checkbox, name). |
data.products | array | An array of product metadata objects for the field. Each object contains:id (string) – The field ID.name (string) – The product, option or shipping label.price (number) – The numeric price. |
Examples
Change the Price of a Custom Product
This example changes the price of products with an inputType of custom to $25.
window.gform.utils.addFilter( 'gform/products/get_product_meta', function( data ) {
if ( data.inputType !== 'custom' ) {
return data;
}
data.products[0].price = 25;
return data;
} );
Placement
Reference the article Adding JavaScript Code to the Frontend of Your Site.
Source Code
This filter is located in assets/js/src/theme/fields/product/parser.js.
Since
This filter was added in Gravity Forms 3.1.3