You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在JetEngine表单添加产品类型下拉框实现前端添加WooCommerce产品?

解决JetEngine前端表单创建WooCommerce可变产品(Variable)的问题

1. 正确配置隐藏字段映射

WooCommerce存储产品类型的元键是_product_type(注意前缀下划线),之前尝试的product_type或_type都不符合规范。在JetEngine表单中添加隐藏字段:

  • 字段名称填写_product_type
  • 默认值设置为variable
  • 确保字段的「保存到元数据」选项处于开启状态

2. 确认JetEngine的WooCommerce集成已启用

进入WordPress后台「JetEngine」→「设置」→「WooCommerce」选项卡,勾选「Enable WooCommerce Integration」,保存设置后刷新表单编辑页面,确保表单能正确识别WooCommerce产品的元字段体系。

3. 用钩子强制设置产品类型(若隐藏字段无效)

如果上述方法仍不生效,添加自定义代码到主题functions.php或代码片段插件:

add_action( 'jet-engine/forms/after-submit', 'force_variable_product_type', 10, 2 );
function force_variable_product_type( $form_id, $post_id ) {
    // 替换为你的目标表单ID
    $target_form = 123;
    if ( $form_id != $target_form || get_post_type( $post_id ) != 'product' ) {
        return;
    }
    // 更新产品类型元数据
    update_post_meta( $post_id, '_product_type', 'variable' );
    // 补充可变产品必要的默认元值
    update_post_meta( $post_id, '_manage_stock', 'no' );
    update_post_meta( $post_id, '_virtual', 'no' );
    update_post_meta( $post_id, '_downloadable', 'no' );
}

记得将代码中的$target_form替换为你的JetEngine表单实际ID。

4. 验证结果

提交测试表单后,进入产品编辑页面查看「产品数据」选项卡是否显示为「可变产品」——产品列表的类型显示可能存在缓存,刷新后台或清除站点缓存后再检查。

内容的提问来源于stack exchange,提问作者Ashley McLean

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 20:57:27