[英]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! 任何帮助将非常感激!
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. 这是我在输入价格后发现的最接近的钩子。 woocommerce_variation_options
will put it before price input 使用woocommerce_variation_options
将把它放在价格输入之前 woocommerce_variation_options_inventory
模板中被称为钩子的是woocommerce_variation_options_inventory
In those cases, you can check yourself what is possible by: 在这些情况下,您可以通过以下方法检查自己的可能性:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.