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:
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:
- Checks if the saved post is a product.
- Ensures it’s not an auto-save or revision.
- Determines if the product is new (
$update
isfalse
). - If new, it sets the product status to
pending
. - 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