Hello guys how are you? Welcome back to my blog therichpost.com. Guys today in this post, I will tell you How add an option for vendors to choose if a product is Brand New or Used in Dokan Multi-Vendor?
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:
1. Guys enable Custom Product Fields in Dokan
Dokan allows you to add custom fields to products. You need to add a condition field (New/Used) in the product edit form.
Add a New Field in the Product Edit Form
You need to modify the dokan_new_product_form
and dokan_product_edit_form
by adding a dropdown.
Add the Field to the Product Edit Form (functions.php)
function dokan_add_product_condition_field() { ?> <div class="dokan-form-group"> <label for="product_condition" class="form-label"><?php esc_html_e('Product Condition', 'dokan'); ?></label> <select name="product_condition" id="product_condition" class="dokan-form-control"> <option value="new"><?php esc_html_e('Brand New', 'dokan'); ?></option> <option value="used"><?php esc_html_e('Used', 'dokan'); ?></option> </select> </div> <?php } add_action('dokan_new_product_after_product_tags', 'dokan_add_product_condition_field'); add_action('dokan_product_edit_after_product_tags', 'dokan_add_product_condition_field');
2. Save the Product Condition Meta Field
Modify the product save function to store the selected condition in product metadata.
function dokan_save_product_condition($product_id) { if (isset($_POST['product_condition'])) { update_post_meta($product_id, '_product_condition', sanitize_text_field($_POST['product_condition'])); } } add_action('dokan_process_product_meta', 'dokan_save_product_condition');
3. Display Product Condition on Product Page
To show the product condition on the product page, modify the single product template:
function dokan_display_product_condition() { global $post; $product_condition = get_post_meta($post->ID, '_product_condition', true); if (!empty($product_condition)) { echo '<p><strong>' . esc_html__('Condition:', 'dokan') . '</strong> ' . esc_html(ucfirst($product_condition)) . '</p>'; } } add_action('woocommerce_single_product_summary', 'dokan_display_product_condition', 25);
4. Display Product Condition in Vendor Dashboard
To allow vendors to see the condition in their product list:
function dokan_add_product_condition_column($columns) { $columns['product_condition'] = __('Condition', 'dokan'); return $columns; } add_filter('manage_edit-product_columns', 'dokan_add_product_condition_column'); function dokan_show_product_condition_column($column, $post_id) { if ($column == 'product_condition') { $condition = get_post_meta($post_id, '_product_condition', true); echo esc_html(ucfirst($condition)); } } add_action('manage_product_posts_custom_column', 'dokan_show_product_condition_column', 10, 2);
Final Outcome
- Vendors can select Brand New or Used when adding/editing products.
- The condition is stored in the database.
- Buyers will see the product condition on the product page.
- Vendors can view the condition in their product list.
Let me know if you need further customization! 🚀
Ajay
Thanks