spivurno
1/31/2019 - 11:54 AM

Gravity Perks // Nested Forms // Copy Parent Entry Properties on Parent Form Submission

<?php
/**
 * Gravity Perks // Nested Forms // Copy Parent Entry Properties on Parent Form Submission
 * http://gravitywiz.com/documentation/gravity-forms-nested-forms/
 */
// Update "123" to your parent form ID.
add_action( 'gform_entry_created_123', function( $entry, $form ) {

	// Specify which properties you would like to populate from the parent.
	// Supports: id, form_id, post_id, date_created, is_starred, is_read, ip, source_url, user_agent, currency, payment_status, payment_date, payment_amount, payment_method, transaction_id, is_fulfilled, created_by, transaction_type, status, date_updated, last_payment_date
	$copy_from_parent = array( 'transaction_id', 'payment_date', 'payment_status' );

	// Specify the field ID of the Nested Form field on your parent form.
	$nested_form_field_id = 1;

	$child_entry_ids = explode( ',', rgar( $entry, $nested_form_field_id ) );
	foreach( $child_entry_ids as $child_entry_id ) {
		foreach( $copy_from_parent as $parent_property ) {
			GFAPI::update_entry_property( $child_entry_id, $parent_property, $entry[ $parent_property ] );
		}
	}

} );