diff --git a/gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php b/gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php index ccae50af3..4851678de 100644 --- a/gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php +++ b/gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php @@ -47,13 +47,14 @@ } } - if ( is_array( $source_values ) ) { - foreach ( $source_values as $input_id => $source_value ) { - $target_input_id = str_replace( "{$source_field->id}.", "{$target['target']}.", $input_id ); - $entry[ $target_input_id ] = $source_value; + $values = is_array( $source_values ) ? array_values( $source_values ) : [ $source_values ]; + + foreach ( $values as $index => $value ) { + $target_input_id = is_array( $source_values ) ? "{$target['target']}." . ( $index + 1 ) : $target['target']; + $entry[ $target_input_id ] = $value; + if ( ! is_array( $source_values ) ) { + break; } - } else { - $entry[ $target['target'] ] = $source_values; } } }