Php 将产品自定义字段添加到WooCommerce中的管理产品批量编辑表单

Php 将产品自定义字段添加到WooCommerce中的管理产品批量编辑表单,php,wordpress,woocommerce,custom-fields,product,Php,Wordpress,Woocommerce,Custom Fields,Product,我在我的WooCommerce产品中添加了一个自定义字段,如以下问题/答案所示: 是否可以将此自定义字段添加到可从管理产品列表页面访问的产品批量编辑特殊页面?是的,可以像链接的问题/答案中那样批量编辑自定义字段“\u text\u field”的产品 您可以在编辑页面的开头或结尾添加此自定义字段 首先,您将使用这个钩子:woocommerce\u product\u bulk\u edit\u start 最后这一条:商业、产品、批量、编辑、结束 自定义字段的代码在此处开头: 代码位于活动子主题

我在我的WooCommerce产品中添加了一个自定义字段,如以下问题/答案所示:


是否可以将此自定义字段添加到可从管理产品列表页面访问的产品批量编辑特殊页面?

是的,可以像链接的问题/答案中那样批量编辑自定义字段“\u text\u field”的产品

您可以在编辑页面的开头或结尾添加此自定义字段

首先,您将使用这个钩子:woocommerce\u product\u bulk\u edit\u start 最后这一条:商业、产品、批量、编辑、结束 自定义字段的代码在此处开头:

代码位于活动子主题或主题的function.php文件中,或者位于任何插件文件中

此代码经过测试并正常工作。您将获得以下信息:


是的,这是可能的,并且没有任何挂钩和代码:

安装插件WooCommerce批量编辑器WOOBE: 转到tab Meta Fields并在那里添加元键,然后按Save按钮 在选项卡设置中,使用新的元键激活列 使用选项卡“批量编辑”执行操作 仅此而已:


p、 美国文件:

你所说的质量是什么意思?@Reigel我选择了几个产品,然后从水平菜单中选择了“编辑”。你看起来:1选择并单击编辑按钮。2-我可以一次编辑多个产品-在谷歌上搜索wordpress批量操作图特。@LoicTheAztec如果您想更新一个数字,如自定义价格字段,按百分比或按固定值增加,那么使用当前值并添加到其中,这会有什么变化?-另外,如果有多个选项,我如何才能看到选择了哪个选项?在$\u请求['fieldname']中是否有任何内容可以告诉我选择了哪个选项?
// 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() {
    ?>
        <div class="inline-edit-group">
            <label class="alignleft">
                <span class="title"><?php _e('T. dostawy', 'woocommerce'); ?></span>
                <span class="input-text-wrap">
                    <select class="change_t_dostawy change_to" name="change_t_dostawy">
                    <?php
                        $options = array(
                            ''  => __( '— No change —', 'woocommerce' ),
                            '1' => __( 'Change to:', 'woocommerce' ),
                        );
                        foreach ( $options as $key => $value ) {
                            echo '<option value="' . esc_attr( $key ) . '">' . $value . '</option>';
                        }
                    ?>
                    </select>
                </span>
            </label>
            <label class="change-input">
                <input type="text" name="_t_dostawy" class="text t_dostawy" placeholder="<?php _e( 'Enter Termin dostawy', 'woocommerce' ); ?>" value="" />
            </label>
        </div>
    <?php
}

// Save the custom fields data when submitted for product bulk edit
add_action('woocommerce_product_bulk_edit_save', 'save_custom_field_product_bulk_edit', 10, 1);
function save_custom_field_product_bulk_edit( $product ){
    if ( $product->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'] ) );
    }
}