我正在尝试为WooCommerce制作一个前端产品编辑器,并有一个为当前用户返回所有产品的循环。我尝试使用重力表单作为编辑器,因此为每个产品显示和填充一个重力表单。然而,我不知道如何处理命名函数,这样就不会为每个产品重新声明它。
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();
?>
有没有办法在函数名中添加计数器或其他变量?因此,按照populate\\u each\\u product的思路。$post->ID ()
还是那种性质?我已经查找了很多,但没有找到在循环中使用函数的参考,所以我担心我正在尝试的是不可能的