• Resolved dejanj

    (@dejanj)


    Hi,

    I followed this instruction to add new field to tmpl-add-product-popup.php.

    https://wedevs.com/support/topic/adding-metadata-to-product-form/

    Here is my code in tmpl-add-product-popup:

    		<!-- Novo polje: Kolicina jednog pakovanja*/ -->
    						<div class="dokan-form-group">
    							<div> Koli?ina jednog pakovanja (neobavezno)</div>
    							<div style = "color:gray;font-size:10px;"> L - litar, ml - Mililitar, Kg - Kilogram, g - Gram</div>
    							<div class="dokan-input-group">
    								<input class="dokan-form-control" name="_new_field" id="_new_field" type="text" placeholder="Primjer: 1L ili 500g" value="<?php echo dokan_posted_input( '_new_field' ); ?>">
    							</div>
    						</div>
    
    

    and this is code in functions.php:

    
    add_action( 'woocommerce_product_options_general_product_data', 'x_add_fields' );
    function x_add_fields() {
     
      global $woocommerce, $post;
      
      echo '<div class="options_group">';
      
      // Number Field
    	woocommerce_wp_text_input( 
    		array( 
    			'id'                => '_new_field', 
    			'label'             => __( 'New Field', 'woocommerce' ), 
    			'placeholder'       => '', 
    			'description'       => __( 'Primjer= 1L, 500ml, 1Kg', 'woocommerce' ),
    			'type'              => 'number', 
    			'custom_attributes' => array(
    				'step' 	=> 'any',
    				'min'	=> '0'
    			) 
    		)
    	);
      
      
      echo '</div>';
    	
    }
    
    // Save 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' );
    
    function x_add_fields_save( $post_id ){
    		
    	// Number Field
    	$woocommerce_new_field = $_POST['_new_field'];
    	if( !empty( $woocommerce_new_field) )
    		update_post_meta( $post_id, '_new_field', esc_attr( $woocommerce_new_field ) );
    	
    }
    

    Why my field is not save on products page?

    • This topic was modified 4 years, 9 months ago by dejanj.
    • This topic was modified 4 years, 9 months ago by dejanj.
    • This topic was modified 4 years, 9 months ago by dejanj.
    • This topic was modified 4 years, 9 months ago by dejanj.
    • This topic was modified 4 years, 9 months ago by dejanj.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @dejanj,

    I am unable to help you with checking the code. But I can help you with guidance that may help.

    You need to modify Dokan product upload template and then you have to add an extra field by overriding the template. After adding the input filed you have to save the value of the field. On that place you have to use do_action( ‘dokan_new_product_added’, $product_id, $post_data ); this hook to save the field data.

    When you will edit the product that time you have to use do_action( ‘dokan_product_updated’, $post_id ); to re-save. As it is a custom development-related support for that reason, I am not authorized to provide more instruction.

    Thanks ??

    Thread Starter dejanj

    (@dejanj)

    Hi Roshni,

    I figured it out, but thanks for your help.

    Have a nice day,
    Dejan

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘New field not saved to Vendors Add new product’ is closed to new replies.