2017-05-18 8 views
6

出荷方法の下で配送領域ページにカスタム項目を追加したい場合は、テキスト入力となり、ユーザーはカスタムメッセージを追加することができますそのメッセージはフロントエンドにあります。配送方法(バックエンド)にカスタム説明項目を追加する方法

データを保存する余分な列を持たないwp_woocommerce_shipping_zone_methodsテーブルにデータが保存されていることがわかりました。だから私は自分のカスタムロジックを使わなければならないと思うが、私はフックの名前は知らない。

だから私の質問は、/私

  1. は、カスタムフィールドを追加できるようにするのに役立ちます任意のフックがあるです。
  2. カスタム列を追加します。

TL; DR: enter image description here

時間の後期

enter image description here

+0

ご覧のテーブルは 'th'と' tfoot'でHTMLのミックスです。詳細は '\ include \ admin \ settings \ views \ html-admin-page-shipping-zone-methods.php'をご覧ください。 –

+0

配送方法の設定のモデルは、Underscore.jsテンプレートにも基づいています。したがって、ビューを変更して入力データを処理するには、カスタムJSを使用する必要があります。データ部分を保存/取得するには、コア設定apiを使用して行い、オプションで保存します。フロントエンドで同じものを表示するには、各WCテンプレートでフックを使用する必要があります。 –

答えて

0

いますが、使用することができます:

:私の意見では

add_action('woocommerce_product_options_general_product_data', 'my_custom_fields'); 

function my_custom_fields() { 
    $field = array(
     //This ID will be use on the _postmeta table as key_name 
     'id' => 'my_custom_message', 
     //Text that goes inside the label tag 
     'label' => 'Message:', 
     //This text will appear on the description column 
     'description' => 'This is a custom message not part of WooCommerce', 
     //Boolean that determines the display of the description 
     'desc_tip' => true, 
     //Standard html input placeholder 
     'placeholder' => 'Type a message', 
    ); 
    woocommerce_wp_text_input($field); 
} 

add_action('woocommerce_process_product_meta', 'save_my_custom_fields'); 

function save_my_custom_fields($post_id) { 
    update_post_meta(
     $post_id, 
     'my_custom_message', 
     esc_attr($POST['my_custom_message']) 
    ); 
} 

$フィールドの配列は最低でも持っている必要があります

$field = array(
    'id' => 'my_custom_message',//This ID will be use on the _postmeta table as key_name 
    'label' => 'Message:',//Text that goes inside the label tag 
    'description' => 'This is a custom message not part of WooCommerce',//This text will appear on the description column 
    'desc_tip' => true,//Boolean that determines the display of the description 
    'placeholder' => 'Type a message',//Standard html input placeholder 
); 

また、次を指定することもできます。データは口ひげがUnderscore.jsテンプレートを触発使用して移入されながら

'class' => 'css-class',//Class attributte for the input tag 
    'style' => 'background:red',//Style attribute for the input tag 
    'wrapper_class' => 'css-class',//Class for the wrapper of the input tag, it is a paragraph 
関連する問題