Home » WooCommerce: Add Custom Field to “Quick Edit”

WooCommerce: Add Custom Field to “Quick Edit”

by adminkys

WooCommerce product custom fields are possibly the most used customization from what I’ve seen over the years on clients’ websites.

Adding custom fields to the product backend is pretty straight forward (including the input fields to be used for editing their values), however there are two additional areas where you need to do more work in order to allow for custom field editing: the “Quick Edit” and the “Bulk Edit” sections (WordPress Dashboard > Products).

We already saw how to allow a new custom field to appear in the Bulk Edit section, so this time we’ll talk about the Quick Edit window. So, how do we add a custom field in there (WordPress Dashboard > Products > Hover on a given product > Quick Edit)?

Well, here’s a fully working snippet for you. Enjoy!

Here’s our custom field now showing in the Quick Edit window on the WooCommerce Products admin page

PHP Snippet: Add Custom Field to Quick Edit @ WooCommerce Products Admin

Please note that inside the snippet you need to replace “_custom_field” with the actual key of your custom field. Given you’ve probably added the custom field with a plugin, you should find its key inside the field settings. If you added it via code, then you’ve defined this key yourself.

/**
 * @snippet       Add Custom Field @ WooCommerce Quick Edit Product
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */
 
add_action( 'woocommerce_product_quick_edit_start', 'tutoraspire_show_custom_field_quick_edit' );

function tutoraspire_show_custom_field_quick_edit() {
global $post;
?>


Custom field: ' . esc_html( get_post_meta( $post_id, '_custom_field', true ) ) . '

‘;
wc_enqueue_js( ”
$(‘#the-list’).on(‘click’, ‘.editinline’, function() {
var post_id = $(this).closest(‘tr’).attr(‘id’);
post_id = post_id.replace(‘post-‘, ”);
var custom_field = $(‘#cf_’ + post_id).text();
$(‘input[name=’_custom_field’]’, ‘.inline-edit-row’).val(custom_field);
});
” );
}

add_action( ‘woocommerce_product_quick_edit_save’, ‘tutoraspire_save_custom_field_quick_edit’ );

function tutoraspire_save_custom_field_quick_edit( $product ) {
$post_id = $product->get_id();
if ( isset( $_REQUEST[‘_custom_field’] ) ) {
$custom_field = $_REQUEST[‘_custom_field’];
update_post_meta( $post_id, ‘_custom_field’, wc_clean( $custom_field ) );
}
}

You may also like