Description
JavaScript action hook that is triggered when any pricing field is modified.
Note: This event was replaced by the gform-products-product_field_changed
event in Gravity Forms 2.9.1.
Usage
<script type="text/javascript">
document.addEventListener('gform_price_change', function(event) {
const { productIds, htmlInput } = event.detail;
// Do something with productIds and htmlInput
console.log(productIds);
});
</script>
Parameters
- event Event Object
Default JS event object. - productIds object
The form id and the id of the product field. - htmlInput string
The HTML input field.
Example
Use wp_head to load the hook.
add_action( 'wp_head', 'do_price_stuff' );
function do_price_stuff() {
?>
<script type="text/javascript">
document.addEventListener('gform_price_change', (event) => {
const { productIds, htmlInput } = event.detail;
console.log(productIds);
// Check if the product field ID is 1
if (productIds['productFieldId'] == 1) {
alert('Price updated');
}
});
</script>
<?php
}
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Since
This filter was added in Gravity Forms version 1.7.
Source Code
This filter is located in gformInitPriceFields() in js/gravityforms.js.