I am trying to make a frontend product editor for WooCommerce, and have a loop that returns all of the products for the current user. I am trying to use gravity forms as the editor, so a single gravity form is displayed and populated for each product. However, I am not sure how to handle naming the function so it is not being re-declared for every product.
global $current_user;
new WP_Query( array( 'author' => $current_user->ID, 'post_type' => 'product' ) );
while ( have_posts() ) {
the_post();
add_filter('gfrom_pre_render_7', 'populate_each_product');
function populate_each_product ($form){
foreach($form["fields"] as &$field){
if($field["id"] == 1){
$field["defaultValue"] = get_post_meta($post->ID, '_virtual', true);
}
}
return $form;
}
}
wp_reset_query();
?>
Is there someway to add a counter or another variable to the function name? So along the lines of populate_each_product . $post->ID () or something of that nature? I have looked around for this quite a bit, but found no reference of using functions inside loops so I am worried what I am trying to do is not possible

query_posts– Tom J Nowell Sep 27 '12 at 12:30