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 🙂
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 ) );
}
}
How can I add “publish date” as extra “bulk edit field” for woocommerce products ?
thanks
Hello Bert. Just change all occurrences of “custom_field” with “post_date” and see if it works
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
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!
Thank you for this article. The Bulk Edit Feature saved a lot of time. Your articles are very helpful.
Awesome
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
But it’s a bulk edit feature. So do you want the value in there “IF” products have all the same value?
Yes that would be great – If all values are the same, then display.
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!
Is that possible to add sales start and end date field in bulk action?
Of course!
Hi,
Thanks for the article. It seems it works very good on simple inputs. What if my custom attribute has dropdown options?
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!