How can I set new vendor products to ‘Pending Review’ while keeping existing products ‘Published’ in WooCommerce (Dokan/WC Vendors)?How can I set new vendor products to ‘Pending Review’ while keeping existing products ‘Published’ in WooCommerce (Dokan/WC Vendors)?

Hello guys how are you? Welcome back to my blog therichpost.com. Guys today in this post, I will tell you How can I set new vendor products to ‘Pending Review’ while keeping existing products ‘Published’ in WooCommerce (Dokan/WC Vendors)?

Guys if you are new in  WordPress or in WooCommerce then please check the below links for some good tutorials:

  1. WooCommerce Hooks
  2. WordPress Tricks
  3. WordPress Hooks
  4. Dokan

Here is the working steps and please follow carefully:

Yes! If you’re using WooCommerce with a multi-vendor plugin like Dokan or WC Vendors, you can achieve this by using the save_post hook in WordPress.

Solution:

You need to check if a product is new and set its status to pending, while keeping existing products published when updated.

Code Snippet:

Add this code to your theme’s functions.php file or a custom plugin:

function set_new_products_pending_review($post_id, $post, $update) {
    // Ensure this is a product
    if ($post->post_type !== 'product') {
        return;
    }

    // Check if this is an auto-save or revision
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }

    // Check user capability (optional: restrict to vendors)
    if (!current_user_can('edit_products')) {
        return;
    }

   // Ensure only vendors are affected
   /*   if (!current_user_can('dokan_edit_product')) {
        return;
    }*/

    // Check if it's an update or a new product
    if (!$update) {
        // New product -> Set status to pending review
        remove_action('save_post', 'set_new_products_pending_review', 10);
        wp_update_post([
            'ID'          => $post_id,
            'post_status' => 'pending',
        ]);
        add_action('save_post', 'set_new_products_pending_review', 10, 3);
    }
}

// Hook into product save event
add_action('save_post', 'set_new_products_pending_review', 10, 3);

How it Works:

  1. Checks if the saved post is a product.
  2. Ensures it’s not an auto-save or revision.
  3. Determines if the product is new ($update is false).
  4. If new, it sets the product status to pending.
  5. Existing products remain published when updated.

This ensures that all new products go into “Pending Review,” while updates to existing ones stay Published.

Ajay

Thanks

By therichpost

Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.