我正在尝试在woocommerce计费部分添加一个额外的字段 . 我想在“名称”字段之前显示“ Headers ”字段 .
我试过这个:
// Add a new checkout field
function custom_filter_checkout_fields($fields){
$fields['billing_title_field'] = array(
'some_field' => array(
'type' => 'text',
'required' => true,
'label' => __( 'Some field' )
)
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'custom_filter_checkout_fields' );
然后
function order_fields($fields) {
$order = array(
"billing_title_field",
"billing_first_name",
"billing_last_name",
"billing_email",
"billing_phone",
"billing_country",
"billing_address_1",
"billing_address_2",
"billing_postcode",
"billing_company"
);
foreach($order as $field)
{
$ordered_fields[$field] = $fields["billing"][$field];
}
$fields["billing"] = $ordered_fields;
return $fields;
}
但这让我没有在第一步中创建的任何字段 . 我很清楚我错过了这个过程的一个重要部分,但我无法弄清楚到底是什么 . 在互联网上搜索没有成功(提供的方法是在计费字段之前或之后添加字段,我需要将其添加到计费字段组中) .
任何帮助表示赞赏!提前致谢!
2 回答
add this plugin
http://phppoet.com/docs/checkout-fields/
and add your field you want
所以我想我找到了答案 . 实际上在第一段代码中我错过了一件重要的事情 . 那看起来应该是这样的:
然后将第二段代码设置为正确的位置 .