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
 * @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

  • WooCommerce: Add Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products. Nothing new so far. But what if […]
  • WooCommerce: Add Column to Orders Table @ WP Dashboard
    The WooCommerce Orders Table, which can be found under WP Dashboard > WooCommerce > Orders, provides us with 7 default columns: Order – Date – Status – Billing – Ship to – Total – Actions. This is used by shop managers to have an overview of all orders, before eventually clicking on a specific one. […]
  • WooCommerce: Display Custom Filters @ WP Dashboard > Products
    If you go to WordPress Dashboard > Products you will find default product admin filters such as “Select a category”, “Filter by product type”, “Filter by stock status”. What if you want to add more custom filters to let your shop managers find products easily? For example, you could add “Filter by product tag” (“product […]
  • WooCommerce: Hide/Show The WP Admin Bar
    In previous WooCommerce versions, new customers could access the WP Admin black bar after purchase. Now this seems fixed. Still, what about other user roles, and what if you want to override this default behavior? Well, here’s a quick snippet for you – feel free to use it in your own WooCommerce site. Enjoy!
  • WooCommerce: Calculate Sales by State
    You’re filing your tax returns and need to know how much you earned in each state… but then find out WooCommerce doesn’t give you this calculation by default within its reports! Don’t worry – today I’ll share a quick snippet so that you can calculate the amount you need in a second. Feel free to […]

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 *