• Resolved OuiT

    (@ouit)


    I use a pro version of wp all import , using woocommerce importer addon I can import csv data to default woocommerce fields, But how I can import the data to custom fields.

    the custom fields code I use is :

    // Display Fields
    add_action( ‘woocommerce_product_options_general_product_data’, ‘woo_add_custom_general_fields’ );

    function woo_add_custom_general_fields() {
    
    	global $woocommerce, $post;
            echo '<div class="options_group">';
    	
    	// Text Field
    	woocommerce_wp_text_input( 
    		array( 
    			'id'          => '_text_field', 
    			'label'       => __( 'My Text Field', 'woocommerce' ), 
    			'placeholder' => 'http://',
    			'desc_tip'    => 'true',
    			'description' => __( 'Enter the custom value here.', 'woocommerce' ) 
    		)
    	);
    	
    	// Number Field
    	woocommerce_wp_text_input( 
    		array( 
    			'id'                => '_number_field', 
    			'label'             => __( 'My Number Field', 'woocommerce' ), 
    			'placeholder'       => '', 
    			'description'       => __( 'Enter the custom value here.', 'woocommerce' ),
    			'type'              => 'number', 
    			'custom_attributes' => array(
    					'step' 	=> 'any',
    					'min'	=> '0'
    			) 
    		)
    	);
    	
    	echo '</div>';
    }
    
    // Save Fields
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
    
    function woo_add_custom_general_fields_save( $post_id ){
    	
    	// Text Field
    	$woocommerce_text_field = isset($_POST['_text_field']) ? $_POST['_text_field'] : '';
    	if( !empty( $woocommerce_text_field ) )
    		update_post_meta( $post_id, '_text_field', esc_attr( $woocommerce_text_field ) );
    		
    	// Number Field
    	$woocommerce_number_field = isset($_POST['_number_field']) ? $_POST['_number_field'] : '';
    	if( !empty( $woocommerce_number_field ) )
    		update_post_meta( $post_id, '_number_field', esc_attr( $woocommerce_number_field ) );
    	
    }
    

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Fields’ is closed to new replies.