2014-04-24 110 views
-2

我試圖在結帳窗體的末尾添加一堆自定義字段,以收集我們需要處理訂單的其他數據。爲WooCommerce結帳後的訂單註釋添加選擇字段

這是我有:

add_action('woocommerce_after_order_notes', 'student_info_fields'); 

function student_info_fields($checkout) { 

    echo '<div id="student_info"><span>The following information below will be used to create an account.</span>'; 

    //This adds a student_name field 
    woocommerce_form_field('student_name', array(
     'type'  => 'text', 
     'class'  => array('form-row-wide'), 
     'label'  => __('Student Name'), 
     'placeholder' => __('eg: "John Smith", "Johnny", etc'), 
     'required' => 'true', 
    ), $checkout->get_value('student_name')); 

    /* I have two other text fields here that follow the same syntax as student_name */ 

    //This adds a student_gender field 
    woocommerce_form_field('student_gender', array(
     'type'  => 'select', 
     'label'  => __('Gender', 'woocommerce'), 
     'placeholder' => _x('', 'placeholder', 'woocommerce'), 
     'required' => 'true', 
     'options'  => array(
      'male' => __('Male', 'woocommerce'), 
      'female' => __('Female', 'woocommerce') 
     ), 
    ), $checkout->get_value('student_gender')); 

    echo '</div>'; 

} 

的文本字段都似乎工作,但是當我加入student_gender場,我的分頁符(全白畫面)。通過在​​數組中調用options數組以及在聲明每個字段後調用$checkout ->get_value...一行,我有點偏離了目標,但我根本不知道該怎麼做。

你可以給我的任何方向將有助於破解這個堅果。感謝您的支持!

+0

看看你的服務器的錯誤日誌知道確切的錯誤。可能這會給你所有你需要的信息。如果不是,請回到問題中並粘貼錯誤。 –

回答

1

我看着它,想通了什麼,我搞砸了。也就是說,它指向我的label聲明,我不認爲它使用的是正確的語法。

我改變了我的代碼:

//This adds a student_gender field 
woocommerce_form_field('student_gender', array(
    'type'  => 'select', 
    'label'  => __('Student Gender'), 
    'placeholder' => _x('', 'placeholder', 'woocommerce'), 
    'required' => 'true', 
    'options'  => array(
      'male' => __('Male', 'woocommerce'), 
      'female' => __('Female', 'woocommerce') 
    ), 
), $checkout->get_value('student_grade')); 
相關問題