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

Leave a Reply