[英]Adding select field after order notes for WooCommerce checkout
我正在尝试在结帐表单的末尾添加一堆自定义字段,以收集我们处理订单所需的其他数据。
这就是我所拥有的:
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 字段时,我的分页符(全白屏)。 通过在student_gender
数组中调用options
数组,以及在声明每个字段后调用$checkout ->get_value...
行,我有点不高兴,但我根本不知道该怎么做。
你能给我的任何方向都会对破解这个坚果很有帮助。 感谢您坚持下去!
我看着它,想出了我在搞砸的事情。 也就是说,它指向我的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' ));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.