0

I am trying to add my custom input field in the quick-edit function of woo commerce products.

I Created a custom input field in my products. I can only edit and save this custom input field if i go directly to the edit page of each product.

Creating the custom input field:

function cfwc_create_custom_field() {
    $args = array(
        'id'            => 'custom_product_code',
        'label'         => __( 'Product Code:', 'cfwc' ),
        'class'                 => 'cfwc-custom-field',
        'desc_tip'      => false,
        'description'   => __( '', 'ctwc' ),
    );
    woocommerce_wp_text_input( $args );
}
add_action( 'woocommerce_product_options_general_product_data', 'cfwc_create_custom_field' );

Saving the custom input field:

function cfwc_save_custom_field( $post_id ) {
    $product = wc_get_product( $post_id );
    $title = isset( $_POST['custom_product_code'] ) ? $_POST['custom_product_code'] : '';
    $product->update_meta_data( 'custom_product_code', sanitize_text_field( $title ) );
    $product->save();
}
add_action( 'woocommerce_process_product_meta', 'cfwc_save_custom_field' );

This code works fine if i edit the product in the edit page. What i want is to edit this custom input field in the quick-edit function of my products so that the user wont need to go to the edit page of each product.

Any help would be appreciated. Thanks.

Ronald Torres
  • 199
  • 2
  • 4
  • 19

1 Answers1

0

Add your above function cfwc_create_custom_field in action like-

add_action( 'woocommerce_product_quick_edit_end', 'cfwc_create_custom_field' );

And save your data in do_action( 'woocommerce_product_quick_edit_save', $product ); hook.

itzmekhokan
  • 2,597
  • 2
  • 9
  • 9