2016-11-08 69 views
1

我搜索如何添加一個自定義字段爲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'])); 
    } 
} 

我該如何編輯這個可變產品? 感謝

回答

-1

只要改變

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'); 

和您的自定義字段將在庫存標籤

相關問題