Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
In WooCommerce product options edit page display a custom field before the SKU

So I've got the following function to add a barcode field in the Product Inventory tab. However this field is being added after all the other content, and I would like to have this before the SKU code.

function add_barcode(){
    global $woocommerce,$post;
    woocommerce_wp_text_input(
        array(
            'id'          => '_barcode',
            'label'       => __('Barcode','woocommerce'),
            'placeholder' => 'Scan Barcode',
            'desc_tip'    => 'true',
            'description' => __('Scan barcode.','woocommerce')
        ));
}
add_action('woocommerce_product_options_inventory_product_data','add_barcode');

Is there anyway to place the function/field before the SKU aka before the actual hook, like something in terms of woocommerce_before_product_options_inventory_product_data?

Thanks for any suggestions in advance.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

IS NOT POSSIBLE TO PLACE ANY CUSTOM FIELD BEFORE THE SKU

You can take a look to html-product-data-inventory.php source code file which displays product inventory fields.

But you can display your 'Barcode' custom field just after the SKU field (for example)

For that you have to hook your custom function in woocommerce_product_options_sku action hook instead. There is also some missing things in your code to display a saved value.

And finally you need another function to save that value when product is saved or updated.

Here is that complete code:

add_action('woocommerce_product_options_sku','add_barcode_custom_field' );
function add_barcode_custom_field(){
    woocommerce_wp_text_input( array(
        'id'          => '_barcode',
        'label'       => __('Barcode','woocommerce'),
        'placeholder' => 'Scan Barcode',
        'desc_tip'    => 'true',
        'description' => __('Scan barcode.','woocommerce')
    ) ); 
}

add_action( 'woocommerce_process_product_meta', 'save_barcode_custom_field', 10, 1 );
function save_barcode_custom_field( $post_id ){
    if( isset($_POST['_barcode']) )
        update_post_meta( $post_id, '_barcode', esc_attr( $_POST['_barcode'] ) );
}

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works for WooCommerce version 2.6+ and 3.0+

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda