WooCommerce: Add Custom Field to “Bulk Actions” > “Edit”

As you know, one of the product bulk edit methods comes with WooCommerce out of the box. It can be found under “WP Dashboard” > “Products” > “Bulk Actions” > “Edit”. For example, you can decrease all prices by 10%, or bulk assign a new product category.

However, if you added a custom product field such as RRP, this won’t show automatically there in the bulk edit form – you’ll therefore need to add it via code. Thankfully, WooCommerce gives us a “hook” we can use to display the input in the bulk edit form. After that, another PHP function will be used to save and store the value.

Easy as pie! Just copy & paste into your functions.php. Enjoy 🙂

Display a custom product field input inside the “Bulk Edit” window @ WooCommerce Products admin

PHP Snippet: Display a Custom Product Field Input @ WordPress Admin > Products > Bulk Edit

/**
 * @snippet       Custom field bulk edit - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 4.0
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

// Note: change all occurrences of "custom_field" with the key of your custom field

add_action( 'woocommerce_product_bulk_edit_start', 'bbloomer_custom_field_bulk_edit_input' );
		   
function bbloomer_custom_field_bulk_edit_input() {
    ?>
    <div class="inline-edit-group">
		<label class="alignleft">
			<span class="title"><?php _e( 'Custom Field', 'woocommerce' ); ?></span>
			<span class="input-text-wrap">
				<input type="text" name="custom_field" class="text" value="">
			</span>
        </label>
    </div>
    <?php
}

add_action( 'woocommerce_product_bulk_edit_save', 'bbloomer_custom_field_bulk_edit_save' );

function bbloomer_custom_field_bulk_edit_save( $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.

8 thoughts on “WooCommerce: Add Custom Field to “Bulk Actions” > “Edit”

  1. Thank you for this article. The Bulk Edit Feature saved a lot of time. Your articles are very helpful.

    1. Awesome

  2. Thank you for this code.

    Could you just add a code for populating bulk edit custom field value with current value? If the field is already populated, it won’t show, it will just be empty.

    Thanks

    1. But it’s a bulk edit feature. So do you want the value in there “IF” products have all the same value?

  3. Is that possible to add sales start and end date field in bulk action?

    1. Of course!

  4. Hi,

    Thanks for the article. It seems it works very good on simple inputs. What if my custom attribute has dropdown options?

    1. Hey Felipe, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

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.