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

Php 更改管理区域中Woocommerce变量产品的自定义字段顺序,php,wordpress,woocommerce,custom-fields,Php,Wordpress,Woocommerce,Custom Fields,我遵循本教程将自定义字段添加到WooCommerce变体中 一切都很顺利 但是,将字段插入仪表板(产品编辑)区域的方法没有提到如何更改仪表板中显示的字段顺序。 . 任何帮助都将不胜感激 使用woocommerce\u variation\u options\u pricing将其置于价格之后(可能需要一些CSS)。这是我在价格输入后发现的最接近的钩子 使用woocommerce\u variation\u options将其置于价格输入之前 以下被称为钩子的模板是woocommerce\u

我遵循本教程将自定义字段添加到WooCommerce变体中

一切都很顺利

但是,将字段插入仪表板(产品编辑)区域的方法没有提到如何更改仪表板中显示的字段顺序。 .

任何帮助都将不胜感激

  • 使用
    woocommerce\u variation\u options\u pricing
    将其置于价格之后(可能需要一些CSS)。这是我在价格输入后发现的最接近的钩子
  • 使用
    woocommerce\u variation\u options
    将其置于价格输入之前
  • 以下被称为钩子的模板是
    woocommerce\u variation\u options\u inventory
在这些情况下,您可以通过以下方式检查自己:

  • 查找相关的Woocommerce模板(在插件目录中)
  • 研究代码以查找
    do_action
    (或
    apply_filter
    for variables)以查看“何时何地可以执行/更新内容”。在您的例子中,
    wp-content/plugins/woocmerce/includes/admin/meta-box/views/html-variation-admin.php:159
  • 有时你是幸运的(仁慈的开发者),有时更少:)
// 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 ) );
    }
}