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 ) );
    }
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

2 thoughts on “WooCommerce: Add Custom Field to “Quick Edit”

  1. Great article helped me a lot.
    I had to make a small modification though. Because I have more than one custom fields that I want to appear in quick edit, I had to change the id of each of my custom fields from ‘#cf_’ + post_id to ‘#cf_[something]’ + post_id and had to have that different for each individual custom field. Hope that helps someone.

    Also is there a way to have radio button-based custom fields appear in the quick edit? How do you set up that?

    1. Thank you for your feedback! In regard to the last question, I have no idea – but I don’t see why that wouldn’t be possible

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published.