Description Field Required like category
-
Hi,
First of all, bundle of thanks for this nice multivendor plugin
I want to required description field like category or set minimum Description length at the time of adding new product. How I do this?
Kindly help me in this regard.Thanks
-
This topic was modified 9 years, 1 month ago by
aqeeliqbal.
-
This topic was modified 9 years, 1 month ago by
-
Hi @aqeeliqbal,
I am assuming that you are talking about the description in product adding pop-up form.
Use this code in your themes functions.php :
add_filter( 'dokan_new_product_popup_args', 'rt_888_check_required_fields', 99, 2 ); function rt_888_check_required_fields( $error, $data ) { $required_fields = array( 'post_excerpt' => __( 'Please include a short description' , 'dokan') ); foreach ( $required_fields as $key => $msg ) { if ( empty( $data[$key] ) ) { return new WP_Error( 'required-missing', $msg ); } } return ''; }Let me know if you need anything else.
Thanks
-
This reply was modified 9 years, 1 month ago by
Rafsun Chowdhury.
Hi @rafsuntaskin,
Bundle of Thanks for your prompt reply
I have disabled the product adding pop up form because in pop up form categories not appear. Is there any way we do this with Add New Product form.
Thanks
hi @aqeeliqbal,
Sorry for replying so lately but it was weekend here.
you just need to change the hook.
add_filter( 'dokan_can_add_product', 'rt_888_check_required_fields', 99, 2 );This will do the job for you.
Thanks
Hi @rafsuntaskin,
After changing the hook, product not created.
Error! Array.
Error! Array.You can check the screenshot from below link
Hi @aqeeliqbal,
Made some adjustments for this , try this now :
add_filter( 'dokan_can_add_product', 'rt_888_check_required_fields', 99, 2 ); function rt_888_check_required_fields( $error, $data ) { $required_fields = array( 'post_excerpt' => __( 'Please include a short description' , 'dokan') ); foreach ( $required_fields as $key => $msg ) { if ( empty( $data[$key] ) ) { $error[] = $msg; } } return $error; }Thanks
Hi @rafsuntaskin,
Working Perfect!
But product not created. Every time when I click “Create Product” button below error msg appear even I have included a short description.
“Error! Please include a short description.”
Ahh!! My bad. It’s not
post_excerptit will bepost_content.You can follow it for other fields as well just duplicate that replace with proper name field.
Thanks
Here is the final version you are looking for :
add_filter( 'dokan_can_add_product', 'rt_888_check_required_fields', 99, 2 ); function rt_888_check_required_fields( $error, $data ) { $required_fields = array( 'post_content' => __( 'Please include a short description' , 'dokan-lite') ); foreach ( $required_fields as $key => $msg ) { if ( empty( $data[$key] ) ) { $error[] = $msg; } } return $error; }Hi @rafsuntaskin,
Bundle of thanks for your cooperation
but error msg not cleared and product not created even I have included both short description and description.
try to understand with below example
If I have not selected the category then error msg appear and if I have selected category then no error msg appear
but whether I have included both short description and description or not in both cases error msg appear.Try this one :
add_filter( 'dokan_can_add_product', 'rt_888_check_required_fields', 99 ); function rt_888_check_required_fields( $error ) { $required_fields = array( 'post_excerpt' => __( 'Please include a short description' , 'dokan-lite'), ); foreach ( $required_fields as $key => $msg ) { if ( empty( $_POST[$key] ) ) { $error[] = $msg; } } return $error; }If you also want to set long description as required. try this :
add_filter( 'dokan_can_add_product', 'rt_888_check_required_fields', 99 ); function rt_888_check_required_fields( $error ) { $required_fields = array( 'post_excerpt' => __( 'Please include a short description' , 'dokan-lite'), 'post_content' => __( 'Please include a description' , 'dokan-lite'), ); foreach ( $required_fields as $key => $msg ) { if ( empty( $_POST[$key] ) ) { $error[] = $msg; } } return $error; }Thanks for being patient.
You are most welcome.
Please let us know if you have further queries.
We really appreciate your support and feedback.
Thanks
hi
i guess do to the same for product price i have to add a line like this?‘_regular_price’ => __( ‘add product price’ , ‘dokan-lite’),
the problem with the code you added in your answere is that if there is an error message, the fields that was filled didnt stored and the vendor have to fill it again. can you please fix that too?
thank you
-
This reply was modified 9 years, 1 month ago by
Siman-Tov Yechiel.
Hi @mastersgate,
Thanks for pointing this out. We will fix this issue in our next update. But I have already fixed some part in our repo in github.
you can copy the file from there.
Thanks
-
This reply was modified 9 years, 1 month ago by
The topic ‘Description Field Required like category’ is closed to new replies.