Image required to upload product
-
Hi, i want to know if i can to make the photo upload to required so the vendors must tu upload an image when they upload a product.
Thank you!
-
Hello @alanfrys ,
Making the image field required will require some customization.
You can follow this video that shows how can you make the image field required: https://www.youtube.com/watch?v=cjLNN3SW0_o&ab_channel=nayemDevs
Thank you ??
Thank you Rashed!
How can i remove the price part? i only want to be the image requierd but not the price
/** * Validation add for product cover image * * @param array $errors * @return array $errors */ function dokan_can_add_product_validation_customized( $errors ) { $postdata = wp_unslash( $_POST ); $featured_image = absint( sanitize_text_field( $postdata['feat_image_id'] ) ); $_regular_price = absint( sanitize_text_field( $postdata['_regular_price'] ) ); if ( isset( $postdata['feat_image_id'] ) && empty( $featured_image ) && ! in_array( 'Please upload a product cover image' , $errors ) ) { $errors[] = 'Please upload a product cover image'; } if ( isset( $postdata['_regular_price'] ) && empty( $_regular_price ) && ! in_array( 'Please insert product price' , $errors ) ) { $errors[] = 'Please insert product price'; } return $errors; } add_filter( 'dokan_can_add_product', 'dokan_can_add_product_validation_customized', 35, 1 ); add_filter( 'dokan_can_edit_product', 'dokan_can_add_product_validation_customized', 35, 1 ); function dokan_new_product_popup_validation_customized( $errors, $data ) { if ( isset( $data['_regular_price'] ) && ! $data['_regular_price'] ) { return new WP_Error( 'no-price', __( 'Please insert product price', 'dokan-lite' ) ); } if ( isset( $data['feat_image_id'] ) && ! $data['feat_image_id'] ) { return new WP_Error( 'no-image', __( 'Please select AT LEAST ONE Picture', 'dokan-lite' ) ); } } add_filter( 'dokan_new_product_popup_args', 'dokan_new_product_popup_validation_customized', 35, 2 );
Thank you very much!
Hello @alanfrys,
You can re-try the below codes –
/** * Validation add for product cover image * * @param array $errors * @return array $errors */ function dokan_can_add_product_validation_customized( $errors ) { $postdata = wp_unslash( $_POST ); $featured_image = absint( sanitize_text_field( $postdata['feat_image_id'] ) ); if ( isset( $postdata['feat_image_id'] ) && empty( $featured_image ) && ! in_array( 'Please upload a product cover image' , $errors ) ) { $errors[] = 'Please upload a product cover image'; } return $errors; } add_filter( 'dokan_can_add_product', 'dokan_can_add_product_validation_customized', 35, 1 ); add_filter( 'dokan_can_edit_product', 'dokan_can_add_product_validation_customized', 35, 1 ); function dokan_new_product_popup_validation_customized( $errors, $data ) { if ( isset( $data['feat_image_id'] ) && ! $data['feat_image_id'] ) { return new WP_Error( 'no-image', __( 'Please select AT LEAST ONE Picture', 'dokan-lite' ) ); } } add_filter( 'dokan_new_product_popup_args', 'dokan_new_product_popup_validation_customized', 35, 2 );
Thast works amazing! thank you very much!
Only one thing more and promise you i finish, how can i add the short description like requiered?
Thank you again!
Hello @alanfrys ,
You can add other fields on the same example code shared above. If I add the short description, the code will be:
/** * Validation add for product cover image * * @param array $errors * @return array $errors */ function dokan_can_add_product_validation_customized( $errors ) { $postdata = wp_unslash( $_POST ); $featured_image = absint( sanitize_text_field( $postdata['feat_image_id'] ) ); $post_excerpt = wp_kses_post( $postdata['post_excerpt'] ); if ( isset( $postdata['feat_image_id'] ) && empty( $featured_image ) && ! in_array( 'Please upload a product cover image' , $errors ) ) { $errors[] = 'Please upload a product cover image'; } if ( isset( $postdata['post_excerpt'] ) && empty( $post_excerpt ) && ! in_array( 'Please add desc' , $errors ) ) { $errors[] = 'Please add desc'; } return $errors; } add_filter( 'dokan_can_add_product', 'dokan_can_add_product_validation_customized', 35, 1 ); add_filter( 'dokan_can_edit_product', 'dokan_can_add_product_validation_customized', 35, 1 ); function dokan_new_product_popup_validation_customized( $errors, $data ) { if ( isset( $data['feat_image_id'] ) && ! $data['feat_image_id'] ) { return new WP_Error( 'no-image', __( 'Please select AT LEAST ONE Picture', 'dokan-lite' ) ); } if ( isset( $data['post_excerpt'] ) && ! $data['post_excerpt'] ) { return new WP_Error( 'no-desc', __( 'Please add description', 'dokan-lite' ) ); } } add_filter( 'dokan_new_product_popup_args', 'dokan_new_product_popup_validation_customized', 35, 2 );
Replace the earlier code with this one.
Thank you ??
Excelent! That works perfect
Thank you very much
Hello guys,
I have the following code, but I want to limit the price validation only for simple product type.
What should I add?
/** * Validation for add product cover image, price and description * * @param array $errors * @return array $errors */ function dokan_can_add_product_validation_customized( $errors ) { $postdata = wp_unslash( $_POST ); $featured_image = absint( sanitize_text_field( $postdata['feat_image_id'] ) ); $_regular_price = absint( sanitize_text_field( $postdata['_regular_price'] ) ); $post_excerpt = wp_kses_post( $postdata['post_excerpt'] ); if ( isset( $postdata['feat_image_id'] ) && empty( $featured_image ) && ! in_array( 'Please upload at least one product image.' , $errors ) ) { $errors[] = 'Please upload at least one product image.'; } if ( isset( $postdata['_regular_price'] ) && empty( $_regular_price ) && ! in_array( 'Please insert the product price.' , $errors ) ) { $errors[] = 'Please insert the product price.'; } if ( isset( $postdata['post_excerpt'] ) && empty( $post_excerpt ) && ! in_array( 'Please add a short description.' , $errors ) ) { $errors[] = 'Please add a short description.'; } return $errors; } add_filter( 'dokan_can_add_product', 'dokan_can_add_product_validation_customized', 35, 1 ); add_filter( 'dokan_can_edit_product', 'dokan_can_add_product_validation_customized', 35, 1 ); function dokan_new_product_popup_validation_customized( $errors, $data ) { if ( isset( $data['feat_image_id'] ) && ! $data['feat_image_id'] ) { return new WP_Error( 'no-image', __( 'Please upload at least one product image.', 'dokan-lite' ) ); } if ( isset( $data['_regular_price'] ) && ! $data['_regular_price'] ) { return new WP_Error( 'no-price', __( 'Please insert the product price.', 'dokan-lite' ) ); } if ( isset( $data['post_excerpt'] ) && ! $data['post_excerpt'] ) { return new WP_Error( 'no-desc', __( 'Please add a short description.', 'dokan-lite' ) ); } } add_filter( 'dokan_new_product_popup_args', 'dokan_new_product_popup_validation_customized', 35, 2 );
Thanks!
- The topic ‘Image required to upload product’ is closed to new replies.