2017-07-20 16 views
0

12個のカスタムフィールドのようなものを追加する必要があるため、WooCommerce製品ページの出荷用タブ設定で追加フィールドを追加することは可能ですか?出荷時タブのWooComerce製品設定ページにカスタムフィールドを追加

私は成功していないいくつかの関連フックを見つけようとしました。私が見つけた唯一の方法は属性の上にありましたが、便利なソリューションではありませんでした。

WooComerce製品設定ページにカスタムタブを追加するにはどうすればいいですか?

ありがとうございました。

答えて

5

これが可能であり、あなたは、この(ここで私は、カスタムテキストフィールドに設定されています)を取得します:ここでは

enter image description here

はコードです:

// Add custom fields to product shipping tab 
add_action('woocommerce_product_options_shipping', 'add_custom_shipping_option_to_products'); 
function add_custom_shipping_option_to_products(){ 
    global $post, $product; 


    echo '</div><div class="options_group">'; // New option group 

    woocommerce_wp_text_input(array(
     'id'   => '_custom_text_field1', 
     'label'  => __('My Text Field one', 'woocommerce'), 
     'placeholder' => 'something', 
     'desc_tip' => 'true', 
     'description' => __('Enter the custom value here.', 'woocommerce'), 
     'value'  => get_post_meta($post->ID, '_custom_meta_field1', true), 
    )); 

    woocommerce_wp_text_input(array(
     'id'   => '_custom_text_field2', 
     'label'  => __('My Text Field two', 'woocommerce'), 
     'placeholder' => 'something', 
     'desc_tip' => 'true', 
     'description' => __('Enter the custom value here.', 'woocommerce'), 
     'value'  => get_post_meta($post->ID, '_custom_meta_field2', true), 
    )); 
} 

// Save the custom fields values as meta data 
add_action('woocommerce_process_product_meta', 'save_custom_shipping_option_to_products'); 
function save_custom_shipping_option_to_products($post_id){ 

    $custom_text_field1 = $_POST['_custom_text_field1']; 
    if(isset($custom_text_field1)) 
     update_post_meta($post_id, '_custom_meta_field1', esc_attr($custom_text_field1)); 

    $custom_text_field2 = $_POST['_custom_text_field2']; 
    if(isset($custom_text_field2)) 
     update_post_meta($post_id, '_custom_meta_field2', esc_attr($custom_text_field2)); 
} 

コードは、関数で行きます。あなたのアクティブな子テーマ(またはテーマ)の、または任意のプラグインファイルのphpファイル。

このコードはWooCommerce 3+でテストおよび

+0

こんにちは、おかげで動作し、それは比較のようなプラグインにも自動的に動作しますか? – Alfista

+0

こんにちは、既にあるディメンションのように1つのフィールドを分割することは可能ですか?既存のフィールド名のテキストを編集することは可能ですか? – Alfista

+0

また、数字が小数点形式で保存されるように設定することもできますか? – Alfista

関連する問題