diff --git a/gp-populate-anything/gppa-populate-child-entries.php b/gp-populate-anything/gppa-populate-child-entries.php index f4470f962..d96c65563 100644 --- a/gp-populate-anything/gppa-populate-child-entries.php +++ b/gp-populate-anything/gppa-populate-child-entries.php @@ -66,7 +66,20 @@ public function populate_parent_entry_id( $value, $field ) { } else { $session = new GPNF_Session( $field->formId ); $cookie = $session->get_cookie(); - $value = rgar( $cookie, 'hash', '' ); + + // try to find cookie, if available. + if ( ! $cookie ) { + $cookie_name = 'gpnf_form_session_'; + $pattern = '/^' . preg_quote( $cookie_name, '/' ) . '[\w\W]*/'; + $matches = preg_grep( $pattern, array_keys( $_COOKIE ) ); + if ( ! empty( $matches ) ) { + foreach ( $matches as $matched_cookie ) { + $cookie = json_decode(stripslashes( $_COOKIE[ $matched_cookie ] ), true); + } + } + } + + $value = rgar( $cookie, 'hash', '' ); } return $value;