Add a product custom field to Admin product bulk edit form in WooCommerce

前端 未结 2 1548
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 06:56

I have added a custom field in my WooCommerce products like in this question/answer:
Display a custom product field before short description in WooCommerce.

Is

2条回答
  •  天涯浪人
    2020-12-17 07:42

    Yes it's possible to bulk edit products for your custom field '_text_field' (as in your linked question/answer).

    You can add this custom field at the beginning or at the end of edit page.

    • For the beginning you will use this hook: woocommerce_product_bulk_edit_start
    • For the end this one: woocommerce_product_bulk_edit_end

    The code (the custom field is at the beginning here):

    // Add a custom field to product bulk edit special page
    add_action( 'woocommerce_product_bulk_edit_start', 'custom_field_product_bulk_edit', 10, 0 );
    function custom_field_product_bulk_edit() {
        ?>
            
    is_type('simple') || $product->is_type('external') ){ $product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id; if ( isset( $_REQUEST['_t_dostawy'] ) ) update_post_meta( $product_id, '_text_field', sanitize_text_field( $_REQUEST['_t_dostawy'] ) ); } }

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    This code is tested and works. You will get this:

提交回复
热议问题