更改WooCommerce可变产品仪表板中自定义字段的顺序

时间:2018-08-05 作者:Patrick

我遵循这个快速/布局良好的wordpress教程,为WooCommerce变体添加自定义字段。

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

一切都很好。。。

但是,将字段插入仪表板(产品编辑)区域的方法没有提到how to change the order of the field as seen in the dashboard..enter image description here

// 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 ) );
    }
}
任何帮助都将不胜感激!

1 个回复
最合适的回答,由SO网友:user141080 整理而成

变体的元框模板在文件中定义html-variation-admin.php. 在那里,您可以找到钩子“woocommerce\\u variation\\u options\\u pricing”。使用这个钩子,您可以将输入字段添加到所需的位置。

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

add_action(\'woocommerce_variation_options_pricing\',\'variation_settings_fields\');

WooCommerce variations meta box with the custome field between price and the stock field

结束

相关推荐

自定义php函数错误不存在

当尚未定义模板时,我能够成功地为新页面设置默认页面模板member_home_page.php. 这在我的本地环境中非常有效,但当我将代码上传到WP Engine上的网站时,我在WordPress的管理页面编辑屏幕顶部发现了这个错误。Warning: call_user_func_array() expects parameter 1 to be a valid callback, function \'set_default_page_template\' not found or invalid fu