【发布时间】:2017-06-19 12:23:41
【问题描述】:
按照 WooCommerce 结帐字段自定义文档:
Customizing checkout fields using actions and filters
我已经通过 functions.php 向 woocommerce 结帐页面添加了一个自定义字段。
我担心是否必须清理该自定义字段的用户输入?
我认为它不需要清理,因为它已传递到帐单字段中,如:$fields['billing'],对吗?
如果不是,我该如何清理这个自定义字段?
创建此自定义字段旨在接受长度不超过 50 的文本字符串(拉丁文)和整数组合。
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
//Adding custom text field
$fields['billing']['billing_username'] = array(
'type' => 'text',
'label' => __('Your Username', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-first'),
'clear' => true
);
return $fields;
}
【问题讨论】:
标签: php wordpress woocommerce checkout sanitization