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        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 4.0
 * @community     https://businessbloomer.com/club/
 */

// 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 custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

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. Follow @rmelogli

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

  1. How can I add “publish date” as extra “bulk edit field” for woocommerce products ?
    thanks

    1. Hello Bert. Just change all occurrences of “custom_field” with “post_date” and see if it works

  2. Works great. Tnx

    But how do you IGNORE a field in bulk? F.i. if you have 2 select field and you want to just bulk edit 1 of them…. How do you ignore the other?

    Thanks.

    Dennis

    1. I see. I believe you need to add a “no change” select option that if selected is not going to update that field. I’m afraid this is custom work; if you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

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

    1. Awesome

  4. 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?

      1. Yes that would be great – If all values are the same, then display.

        1. Thanks Alex, I guess 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!

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

    1. Of course!

  6. 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? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *