WooCommerce: Add Custom Field to “Quick Edit”

WooCommerce: Add Custom Field to “Quick Edit”

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 CustomizeWoo.com FREE * @author        Rodolfo Melogli * @testedwith    WooCommerce 6 * @donate $9     https://businessbloomer.com/bloomer-armada/ */ add_action( 'woocommerce_product_quick_edit_start', 'bbloomer_show_custom_field_quick_edit' );function bbloomer_show_custom_field_quick_edit() {	global $post;	?>	<label>		<span class="title">Custom field</span>		<span class="input-text-wrap">			<input type="text" name="_custom_field" class="text" value="">		</span>	</label>	<br class="clear" />	<?php}add_action( 'manage_product_posts_custom_column', 'bbloomer_show_custom_field_quick_edit_data', 9999, 2 );function bbloomer_show_custom_field_quick_edit_data( $column, $post_id ){    if ( 'name' !== $column ) return;    echo '<div>Custom field: <span id="cf_' . $post_id . '">' . esc_html( get_post_meta( $post_id, '_custom_field', true ) ) . '</span></div>';	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', 'bbloomer_save_custom_field_quick_edit' );function bbloomer_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 ) );    }}

WooCommerce: Add Custom Field to “Quick Edit” .