简体   繁体   English

在管理区域中更改Woocommerce变量产品的自定义字段的顺序

[英]Change the order of custom field for Woocommerce variable products in admin area

I followed this tutorial for adding custom fields into WooCommerce variations. 我按照本教程将自定义字段添加到WooCommerce版本中。

http://www.remicorson.com/woocommerce-custom-fields-for-variations/ http://www.remicorson.com/woocommerce-custom-fields-for-variations/

Everything worked great... 一切都很好...

However the method for inserting the field into the dashboard (product edit) area doesn't mention how to change the order of the field as seen in the dashboard . 但是,将字段插入仪表板(产品编辑)区域的方法没有提到如何更改仪表板中显示的字段顺序 . 在此处输入图片说明

// Add Variation Settings
add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
// Save Variation Settings
add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );

function variation_settings_fields( $loop, $variation_data, $variation ) {
    // Text Field
    woocommerce_wp_text_input( 
        array( 
            'id'          => '_text_field[' . $variation->ID . ']', 
            'label'       => __( 'My Text Field', 'woocommerce' ), 
            'placeholder' => 'http://',
            'desc_tip'    => 'true',
            'description' => __( 'Enter the custom value here.', 'woocommerce' ),
            'value'       => get_post_meta( $variation->ID, '_text_field', true )
        )
    );

}

function save_variation_settings_fields( $post_id ) {
    // Text Field
    $text_field = $_POST['_text_field'][ $post_id ];
    if( ! empty( $text_field ) ) {
        update_post_meta( $post_id, '_text_field', esc_attr( $text_field ) );
    }
}

Any help would be much appreciated! 任何帮助将非常感激!

  • Using woocommerce_variation_options_pricing will put it after the price (it may need some CSS). 使用woocommerce_variation_options_pricing会将其放在价格之后(可能需要一些CSS)。 It's the closest hook I found after price input. 这是我在输入价格后发现的最接近的钩子。
  • Using woocommerce_variation_options will put it before price input 使用woocommerce_variation_options将把它放在价格输入之前
  • Following called hook in template is woocommerce_variation_options_inventory 模板中被称为钩子的是woocommerce_variation_options_inventory

In those cases, you can check yourself what is possible by: 在这些情况下,您可以通过以下方法检查自己的可能性:

  • finding the related Woocommerce template (in plugin directory) 查找相关的Woocommerce模板(在插件目录中)
  • studying the code to find do_action (or apply_filter for variables) to see "where and when you can do/update stuff". 研究代码以查找do_action (或对变量使用apply_filter )以查看“何时何地可以执行/更新内容”。 In your case wp-content/plugins/woocommerce/includes/admin/meta-boxes/views/html-variation-admin.php:159 在您的情况下wp-content/plugins/woocommerce/includes/admin/meta-boxes/views/html-variation-admin.php:159
  • sometimes your are lucky (merciful devs), sometimes less :) 有时候你很幸运(富有发展力的开发者),有时候却少了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WooCommerce 电子邮件订单项目中显示可变产品的产品自定义字段 - Display a product custom field for variable products in WooCommerce email order items 在 WooCommerce 管理员订单项目上显示产品自定义字段也适用于可变产品 - Display product custom fields on WooCommerce Admin Order Items also for variable products 管理员按自定义字段搜索 Woocommerce 订单 - Admin search Woocommerce order by custom field 仅在 WooCommerce 中的自定义类型的管理产品上添加字段 - Add a field only on admin products from a custom type in WooCommerce 将自定义字段添加到 Woocommerce 产品快速编辑管理面板 - Add custom field to Woocommerce products quick edit admin panel 在Woocommerce订单详细信息管理区域中显示自定义数据 - Show Custom Data in Woocommerce Order Details Admin Area WooCommerce:添加自定义字段以订购元和管理订单 - WooCommerce: add custom field to order meta and admin order 在 Woocommerce 管理订单页面中保存订单项目自定义字段 - Save Order item custom field in Woocommerce Admin order pages 在 Woocommerce 管理订单列表“订单”现有列中添加自定义字段 - Add a custom field in Woocommerce admin order list "Order" existing column 批量更改WooCommerce变量产品上属性下拉列表的顺序 - Bulk change the order of attributes dropdowns on WooCommerce variable products
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM