Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter adrien99

    (@adrien99)

    Finally, i succeeded by going through the child theme file “functions.php” :

    // Display Fields
    
    add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
    
    // Save Fields
    
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
    
    function woo_add_custom_general_fields() {
    
    global $woocommerce, $post;
    
    // Text Field
    
    woocommerce_wp_text_input(
    
        array(
    
            'id' => 'barcode',
    
            'label' => __( 'Code Barre', 'woocommerce' ),
    
            'placeholder' => 'code barre',
    
            'desc_tip' => 'true',
    
            'description' => __( 'Product barcode.', 'woocommerce' )
    
        )
    
    );
    
    }
    
    function woo_add_custom_general_fields_save( $post_id ){
    
    // Textarea
    
    $woocommerce_barcode = $_POST['barcode'];
    
    if( !empty( $woocommerce_barcode ) )
    
        update_post_meta( $post_id, 'barcode', esc_html( $woocommerce_barcode ) );
    
    }
    Saif

    (@babylon1999)

    Hello @adrien99,

    Thank you for sharing the solution with the community! ??

    I will mark the thread as solved, please feel free to create a new one if you have any other questions.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add custom meta data for products’ is closed to new replies.