How to Add Conditional Product Attributes by Category in Dokan (WooCommerce Guide)?How to Add Conditional Product Attributes by Category in Dokan (WooCommerce Guide)?

Hello guys how are you? Welcome back to my blog therichpost.com. Guys today in this post, I will tell show you How to Add Conditional Product Attributes by Category in Dokan (WooCommerce Guide)?

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 for how to show or hide product attributes in Dokan based on selected categories. A step-by-step guide with code examples to create dynamic, category-specific fields for vendors in WooCommerce multivendor stores. and please follow carefully:


In Dokan (WooCommerce multivendor plugin), managing conditional attributes per product category isn’t supported natively out of the box, but yes β€” it is possible using a combination of:

βœ… Approaches:

1. Custom Code via Hooks (Recommended for Developers)

Guys we can conditionally display or require product attributes in the vendor dashboard based on the selected product category by hooking into:

  • dokan_product_edit_after_main
  • dokan_new_product_after_main

Use JavaScript (with jQuery) to show/hide attribute fields depending on the selected category, and PHP to handle save logic.

Example:

add_action( 'dokan_new_product_after_main', 'add_conditional_attribute_fields' );
add_action( 'dokan_product_edit_after_main', 'add_conditional_attribute_fields' );

function add_conditional_attribute_fields( $post, $post_id = 0 ) {
    ?>
    <script>
      jQuery(document).ready(function($) {
        $('#product_cat').on('change', function () {
          let selectedCat = $(this).val();

          // Example: Show a field if category ID is 123
          if (selectedCat.includes("123")) {
            $('#my-custom-attribute').show();
          } else {
            $('#my-custom-attribute').hide();
          }
        }).trigger('change'); // Trigger on page load
      });
    </script>
    <div id="my-custom-attribute" style="display:none;">
        <label for="custom_field">Extra Detail</label>
        <input type="text" name="custom_field" value="" />
    </div>
    <?php
}

2. Use ACF (Advanced Custom Fields) + Conditional Logic

  • Use ACF Pro to add custom fields.
  • Assign fields conditionally to product categories.
  • Integrate with Dokan via the dokan_product_edit_after_main hook.

3. Dokan Pro: Custom Product Attribute Groups (Manual Workaround)

While not conditional by default, you can create attribute groups for different categories. Vendors will manually select the right ones, but this doesn’t enforce strict conditions.


πŸ›  Want Full Dynamic Behavior?

If you’re building a more advanced system (e.g., per-category attribute templates or dynamic form generation), let me know β€” I can help you architect it cleanly using Ajax, REST API, and Dokan hooks.

Would you like a fully working code snippet or plugin customization walkthrough?

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.