• Resolved briangelhaus

    (@briangelhaus)


    How do I add an error if a field is empty on /mytheme/dokan/products/new-product.php?

    I see dokan is looping throw errors with:
    dokan()->dashboard->templates->products->has_errors()

    How do I add an error to this function?

    I’m currently using this function to add a new field and want to make it required

    function x_add_fields_save( $post_id ){
        // save condition when user adds a new product
        if(isset($_POST['item_condition'])){	
    	    $condition = $_POST['item_condition'];
    	    if(!empty($condition)){
    	        update_post_meta( $post_id, 'item_condition', esc_attr($condition) );
    	    }
    	}
    }// add fields
    add_action( 'woocommerce_process_product_meta', 'x_add_fields_save' );
    add_action( 'dokan_process_product_meta', 'x_add_fields_save' );
    add_action( 'dokan_new_product_added', 'x_add_fields_save' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @briangelhaus ,

    You may would like to take a look at the file – dokan-lite\includes\Dashboard\Templates\Products.php here see the function – handle_product_add(). There is also a filter available to add new error parameter – dokan_can_add_product.

    I hope this information helps you to make your customization.

    Thank you.

    Thread Starter briangelhaus

    (@briangelhaus)

    @rur165 Thanks! dokan_can_add_product works for me. I used it like….

    function dokan_add_product_errors($errors) {
    	//echo '<pre>'; print_r($_POST); echo '</pre>';
    	//echo '<pre>'; print_r($errors); echo '</pre>';
    	
    	if(isset($_POST['item_condition'])){	
    	    $condition = $_POST['item_condition'];
    	    if(empty($condition)){
    	        $errors[] = 'Condition is required';
    	    }
    	}
    	return $errors;
    }
    add_filter( 'dokan_can_add_product', 'dokan_add_product_errors', 121 );

    Hello @briangelhaus

    Could You please help me ?

    i would like to make product featured image & Regular Price required also

    i tried to use your mentioned code above but it doesn’t work for me any more

    so could you please help me or to tell me where could i place that code ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add errors if empty field on new-product.php’ is closed to new replies.