添加自定义字段woocomerce(变量产品)

问题描述:

我搜索如何添加一个自定义字段为woocomerce中的viriable产品。我已经这样做了,但只适用于简单的产品。添加自定义字段woocomerce(变量产品)

add_action('woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields'); 
function wc_custom_add_custom_fields() { 
    // Print a custom text field 
    woocommerce_wp_text_input(array(
     'id' => '_custom_text_field', 
     'label' => 'Custom Text Field', 
     'description' => 'This is a custom field, you can write here anything you want.', 
     'desc_tip' => 'true', 
     'placeholder' => 'Custom text' 
    )); 
} 
add_action('woocommerce_process_product_meta', 'wc_custom_save_custom_fields'); 
function wc_custom_save_custom_fields($post_id) { 
    if (! empty($_POST['_custom_text_field'])) { 
     update_post_meta($post_id, '_custom_text_field', esc_attr($_POST['_custom_text_field'])); 
    } 
} 

我该如何编辑这个可变产品? 感谢

只要改变

add_action('woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields'); 

add_action('woocommerce_product_options_inventory_product_data', 'wc_custom_add_custom_fields'); 

和您的自定义字段将在库存标签