How to add a new field on product upload form – Dokan Multivendor

This will be the most awaited blog post for Dokan users. Dokan powered marketplaces are advanced and its users are building different kinds of a marketplace with unique requirements. To meet the marketplace requirements, sometimes it is necessary to modify the plugin. One of the common modification is adding a new field on the product upload form of Dokan.

It is easy to add a new field on the backend WooCommerce with ACF but Dokan does not populate that field automatically. To add a new field, you might need to add a little bit of code. So, I thought to write a full blog with code example so that it can save users time and money.

How to add a new field?

If you are trying to read my post and add a field then install a child-theme on your website. I have done the code in 4 steps –

  1. Added a field on product upload form (With pop-up or without pop-up)
  2. Saved and updated field value while saving the product
  3. Showing the extra field on product edit page
  4. Also, showing the extra field data on single product page 🙂

Now, open your child-theme functions.php and paste the below code –

Now, check the product upload form where you will get the new field after that TAG field –

Extra field on upload form

Please note that I have used this action to add the field after the tag field – dokan_new_product_after_product_tags which will add the field after the tag. If you want multiple fields then you can add multiple

Now, you can fill the form and create your product which will redirect you to the product edit page with the new custom field value –

Product Edit Page

I have used these actions to save and update product meta – dokan_new_product_added & dokan_new_product_updated

Best theme for Dokan Multivendor

To show the field on the edit product page, I just used this action – dokan_product_edit_after_product_tags

The last part of the code is to show new field data on single product page. To show on the single product page, I have used this action- woocommerce_single_product_summary

Single product page

If you need to change the field type or need to add more fields, then you can follow my above code and write your one.

Check this full video to learn how to add multiple fields!

Subscribe the channel
Check this video to add multiple fields

40 thoughts on “How to add a new field on product upload form – Dokan Multivendor

  1. Hi Nayem,

    Thanks for sharing such important information and looking forward to more blogs on the Dokan plugin.
    I want to add a new field in the product upload form, where the vendor can add an extra fee (for example packing and handling fee). This field needs to be carried forward to the single product page and the cost needs to be replicated in cart.
    If you could share such a code to be added to functions.php that will be nice.
    Thanks in advance
    Regards
    Paul

    1. Hello Paul,

      I have already shared the way how you can add a field, save the field, and show it on single product page. The way you are looking for is a similar modification with extended functionality. I am unable to do anything here for now but you can follow my step and add your own field.

  2. Great article – Thanks for putting this together.

    Could you please elaborate on how to display the “Product Code” on the Product page using the hook method you have mentioned ..

    “The last part of the code is to show new field data on single product page. To show on the single product page, I have used this action- woocommerce_single_product_summary”

    1. To show data on single product page, WooCommerce has hook-like after the title, after description, etc. I have used woocommerce_single_product_summary and print the field value on through the hook. I checked global $product and then checked product ID 🙂

  3. Hi Nayem, thank you so much for this long-awaited tutorial. I followed your instructions and now have a new field.

    My php knowledge is quite limited at this stage of my life, I was wondering if you can give me a hint on how to reposition the new field.

    I would like to place the new field below the ‘Product Name’ field. Any help is greatly appreciated.

    Thank you
    Marc

    1. Hello,

      The hook I have used only allows add the filed after the category. There is no available filter to place the field after the title. Now, the only way is overriding template file directly via your child theme then insert the HTML field.

      1. Ok, understood. I will override template file via child theme. Thank you kindly for your fantastic article, your code, and for answering my question!

    2. Hello,

      The hook I have used only allows adding the filed after the category. There is no available filter to place the field after the title. Now, the only way is overriding template file directly via your child theme then insert the HTML field.

      1. Do you have anything that you can reference to give an example? I’ve tried to tweak the code several times to reflect a drop down/select box and options, but nothing works.

      2. Hello again – if you can’t help with creating a dropdown, would you mind extending this snippet to include a shortcode that can be used with Elementor to display the field data? That would be really great! Thank you.

  4. Hello,
    I read your post and found it very interesting and useful because I have the same need “To Add A New Field On Product Upload Form”.
    But when I go to edit my functions.php file which is located in child theme ( I am using atra -child theme) it gives me an error and does not load my page.
    Am I doing something wrong or should I copy this code to a different file?

  5. Hello! I am making WordPress Multivendor marketplace and I am using woocommerce + dokan. I have one problem, and I don’t know how to fix it.

    The problem is how to define “New Product” to vendors because there are necessary fields they have to fill. New Product pop up have to be precisely predefined with different fields for entry.

    I will give concrete example. There are 4 primary categories, and vendor choose one of them, and depending on the category, it should appear different fields which he needs to fill in New Product pop up.

    The problem is bigger because, he needs to get specific fields for entry, even depending on subcategory which he choose, because, every category doesn’t have the same informations.

    Are there any plugin which can fix this problem, or simply to customize code on some way ?

    Thank You very much. I really appreciate Your help and Your time.
    Best regards

  6. Thanks for this great article. 1 question though…

    I have ACF field group and how can I add it in the Dokan Product Upload Form?

      1. Thanks for reply, is there any alternative to have customs field in dokan product upload form with conditional logic?

  7. Hi,
    I got a question that is about adding new fileds in dokan, but not concerning the procuct upload.
    I tried to contact you with the contact form, but that didn’t work.

    Here is my question:
    Dokan offers an option called vendor verification, so basically an option for admins to verify vendors. As default there are only three verifaction steps, one for the ID, one for the store adress and one for social networks. (https://prnt.sc/uwvi7k)
    I was wondering if it is possible to add additional steps, so I can verify the origin of my vendors products for example?
    Maybe this might be a good topic for one of your next blog posts, beacuse I’m sure this is interesting for more dokan admins.

  8. Hi Nazmul,

    Great article and just in time.
    What I actually wanted to do is improve the vendors capability of uploading images and I wanted that a click on the default image button (square) would invoke something like that: https://www.uploader.win/ – that will allow vendors to load directly from their Instagram account.

    Do you think it is possible?

    Thanks!

  9. This message appeared .. why?

    Your PHP code changes were rolled back due to an error on line 30 of file C:\wamp64\www\wordpress\wp-content\themes\ProductID\functions.php. Please fix and try saving again.

    syntax error, unexpected ‘<', expecting end of file

  10. Hi, is it possible to add such a field with a plugin like “snippets” so that I don’t have to use a child theme?

    Best regards,
    Sebastian

      1. Hi, thanks for the quick response!
        I’m not quite sure what this means “as long there has a function with action/hook”, but I tried it and it works.

        I want to add more of these fields, what do I have to change or which parts of your code have to be changed if I want to implement a second field?

        Is there a way to effect the position of the fields in the product edit page and in the product detail page?

        Best regards,
        Sebastian

        1. You can follow the same method and multiple HTMl field with different field name like new_field_1, 2 and then save the meta value-

          if ( ! empty( $postdata[‘new_field’] ) ) {
          update_post_meta( $product_id, ‘new_field’, $postdata[‘new_field’] );
          }
          if ( ! empty( $postdata[‘new_field’] ) ) {
          update_post_meta( $product_id, ‘new_field’, $postdata[‘new_field_1’] );
          }
          if ( ! empty( $postdata[‘new_field’] ) ) {
          update_post_meta( $product_id, ‘new_field’, $postdata[‘new_field’_2] );
          }
          }

    1. Wow thank you that is great!
      In your video you did not show how to display both fields in the frontend for the customer, like on the product detail page – can you explain how to do this?

      I followed your steps like in the video, but I can not enter differents values for the two fields, the first one overrides the second.
      I’m also currently facing the problem that I can not change the value of any of the both fields, like if it is “12345” and I want to change it to “6789” and save the product it still remains on “12345”?
      Hope you can help me out!

      Best regards,
      Sebastian

  11. trying to add a form field of dropdown in the product such as conditions of the product.

    I have coded it accordingly to reflect input type as dropdown in my conditions field. However, i am not sure where to input the options for the dropdown (new, used or open box). can you please help.

    Here is the code:

    /*
    * Adding extra field on New product popup/without popup form
    */

    add_action( ‘dokan_new_product_after_product_tags’,’new_product_field’,10 );

    function new_product_field(){ ?>

    <input type="text" class="dokan-form-control" name="new_field" placeholder="”>

    <input type="text" class="dokan-form-control" name="new_field_1" placeholder="”>

    <input type="dropdown" class="dokan-form-control" name="new_field_2" placeholder="”>

    <input type="hidden" name="new_field" id="dokan-edit-product-id" value="”/>

    __( ‘product code’, ‘dokan-lite’ ), ‘value’ => $new_field ) ); ?>

    <input type="hidden" name="new_field_1" id="dokan-edit-product-id" value="”/>

    __( ‘product License’, ‘dokan-lite’ ), ‘value’ => $new_field_1 ) ); ?>

    <input type="hidden" name="new_field_2" id="dokan-edit-product-id" value="”/>

    __( ‘product code’, ‘dokan-lite’ ), ‘value’ => $new_field_2 ) ); ?>

    get_id(), ‘new_field’, true );

    if ( ! empty( $new_field ) ) {
    ?>

    <?php
    }
    }

  12. You have to follow a similar method. Just duplicate the below codes and change the meta –

    $new_field = get_post_meta( $product->get_id(), ‘new_field’, true );

    if ( ! empty( $new_field ) ) {
    ?>

  13. Hi
    Thank you so much, you saved me weeks of work, I managed to do this in 10 minutes. I now only need to make the new field be compulsory to fill for the vendors, what do I need to add to the above code?

      1. Hi thanks, now I am trying to add an additional field but I am failing, it keeps breaking the site, is the code clashing with the one I placed for the other field?

  14. Hello! I need to show the custom input in the create new product page if the category of the product is x, how can i do it?
    PS. i tested the code without any change, but diden`t showed the input custom input in the edit product page, i`m using the newest version of dokan.

  15. Other thing, can i display the products in the home page based in the data of the new input? for example, i made a new input to display a dropdown that says if the product is new or used, and i want to display only used products in the home page tab.

Leave a Reply

Your email address will not be published. Required fields are marked *