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:
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?
Okay guys this is it and if you will have any query then feel free to comment below.
Ajay
Thanks