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

如何在WooCommerce网站前端创建免费的产品提交表单?

Hey there! Totally get wanting a free way to build a front-end product submission form for your WooCommerce store—paid tools like the one you referenced aren’t always feasible. Let’s walk through three solid, no-cost approaches you can implement right away:

1. Custom Code Implementation (Full Control)

If you’re comfortable tinkering with code, this gives you complete flexibility without relying on plugins. Here’s a step-by-step breakdown:

Step 1: Create the Form Template

First, make a new template file (e.g., product-submission-form.php) in your child theme folder, then add this HTML form:

<?php
// Check if user is logged in (adjust roles as needed)
if (!is_user_logged_in() || !current_user_can('edit_posts')) {
    echo "<p>Please log in as a vendor to submit products.</p>";
    return;
}
?>

<form id="wc-product-submission" method="post" enctype="multipart/form-data">
    <label for="product-title">Product Title *</label>
    <input type="text" id="product-title" name="product_title" required>

    <label for="product-description">Product Description *</label>
    <textarea id="product-description" name="product_description" required></textarea>

    <label for="product-price">Price *</label>
    <input type="number" id="product-price" name="product_price" step="0.01" required>

    <label for="product-category">Category</label>
    <?php
    wp_dropdown_categories(array(
        'taxonomy' => 'product_cat',
        'name' => 'product_category',
        'show_option_none' => 'Select a category'
    ));
    ?>

    <label for="product-image">Product Image</label>
    <input type="file" id="product-image" name="product_image" accept="image/*">

    <input type="hidden" name="action" value="submit_woocommerce_product">
    <?php wp_nonce_field('product_submission_nonce', 'product_submission_nonce'); ?>
    <button type="submit">Submit Product</button>
</form>

Step 2: Handle Form Submission

Add this code to your child theme’s functions.php file to process the form and create the WooCommerce product:

add_action('admin_post_nopriv_submit_woocommerce_product', 'handle_product_submission');
add_action('admin_post_submit_woocommerce_product', 'handle_product_submission');

function handle_product_submission() {
    // Verify nonce and user permissions
    if (!isset($_POST['product_submission_nonce']) || !wp_verify_nonce($_POST['product_submission_nonce'], 'product_submission_nonce')) {
        wp_die('Invalid submission.');
    }
    if (!current_user_can('edit_posts')) {
        wp_die('You don\'t have permission to submit products.');
    }

    // Sanitize input data
    $title = sanitize_text_field($_POST['product_title']);
    $description = wp_kses_post($_POST['product_description']);
    $price = sanitize_text_field($_POST['product_price']);
    $category = isset($_POST['product_category']) ? intval($_POST['product_category']) : 0;

    // Create WooCommerce product
    $product_data = array(
        'post_title' => $title,
        'post_content' => $description,
        'post_status' => 'draft', // Set to 'publish' if you want auto-published
        'post_type' => 'product',
        'post_author' => get_current_user_id()
    );
    $product_id = wp_insert_post($product_data);

    // Set product meta
    update_post_meta($product_id, '_price', $price);
    update_post_meta($product_id, '_regular_price', $price);
    wp_set_object_terms($product_id, 'simple', 'product_type'); // Set to variable/grouped if needed

    // Assign category
    if ($category) {
        wp_set_object_terms($product_id, $category, 'product_cat');
    }

    // Handle product image upload
    if (!empty($_FILES['product_image']['name'])) {
        require_once(ABSPATH . 'wp-admin/includes/image.php');
        require_once(ABSPATH . 'wp-admin/includes/file.php');
        require_once(ABSPATH . 'wp-admin/includes/media.php');

        $attachment_id = media_handle_upload('product_image', $product_id);
        if (!is_wp_error($attachment_id)) {
            set_post_thumbnail($product_id, $attachment_id);
        }
    }

    // Redirect back to form with success message
    wp_redirect(add_query_arg('submitted', 'true', wp_get_referer()));
    exit;
}

Step 3: Add the Form to a Page

Use a shortcode to embed the form anywhere. Add this to functions.php:

add_shortcode('wc_product_submission_form', 'render_product_submission_form');

function render_product_submission_form() {
    ob_start();
    get_template_part('product-submission-form');
    return ob_get_clean();
}

Now just add [wc_product_submission_form] to any page or post to display the form.

2. Free Plugin Solutions (Quick Setup)

If coding isn’t your thing, these free plugins do the heavy lifting:

  • WP User Frontend (Free Version): This plugin lets you create custom post type forms, including WooCommerce products. After installing, go to WP User Frontend > Post Forms and create a new form mapped to the product post type. You can add fields for title, description, price, categories, and even images. Set permissions so only specific roles (like Vendors) can submit, and choose whether products are saved as drafts or published immediately.

  • Product Upload for WooCommerce: A lightweight plugin built specifically for this use case. It adds a front-end upload form where users can submit products with basic details (title, description, price, category, images). You can configure settings to moderate submissions (set products to draft) and restrict access to logged-in users only.

3. Gutenberg + ACF (Visual Building)

If you prefer visual tools, combine the free Advanced Custom Fields (ACF) plugin with Gutenberg:

  1. Install ACF and create a field group with product fields (title, description, price, image, category).
  2. Use Gutenberg’s Form block (or a free form block plugin like Forminator Free) to build a front-end form that collects these fields.
  3. Add a small snippet to functions.php to take the form data, create a WooCommerce product, and map the ACF fields to product meta (similar to the custom code approach above).

Key Tips for All Methods

  • Moderation: Always set submitted products to draft by default so you can review them before publishing—prevents spam and low-quality listings.
  • Permissions: Restrict form access to specific user roles (e.g., vendor, contributor) using current_user_can() in code or plugin settings.
  • Validation: Add client-side validation (HTML5 required attributes) and server-side validation in code to ensure data is clean.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 11:05:24