Skip to content

Commit a225691

Browse files
committed
gpnf-override-parent-merge-tag-on-submission.php: reprocess calculations on submission based on changed parent form values
1 parent a3346e1 commit a225691

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ function gpnf_override_parent_merge_tags( $entry, $form ) {
4646
gpnf_override_child_entry_input_value( $entry, $field, $child_field->id, $child_field->defaultValue );
4747
}
4848
}
49+
50+
// Reprocess calculations based off of the potentially changed parent value.
51+
$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
52+
53+
foreach ( $child_entry_ids as $child_entry_id ) {
54+
foreach ( $child_form['fields'] as $child_field ) {
55+
if ( in_array( $child_field->id, $exclude_field_ids ) ) {
56+
continue;
57+
}
58+
59+
if ( ! $child_field->has_calculation() ) {
60+
continue;
61+
}
62+
63+
// @todo do calculated product fields need to be accounted for differently?
64+
$child_entry = GFAPI::get_entry( $child_entry_id );
65+
$calculated_value = $child_field->get_value_save_entry( null, $child_form, $child_field->id, $child_entry_id, $child_entry );
66+
GFAPI::update_entry_field( $child_entry_id, $child_field->id, $calculated_value );
67+
}
68+
}
4969
}
5070
}
5171

0 commit comments

Comments
 (0)