我試圖在woocommerce結算部分添加一個附加字段。我想在「名稱」字段之前顯示「標題」字段。woocommerce附加結算字段
我已經試過這樣:
// 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;
}
但這返回我沒有現場我在第一步中創建。我清楚地知道我錯過了這個過程的一個非常重要的部分,但我無法弄清楚究竟是什麼。在互聯網上搜索沒有成功(提供的方法是在計費字段之前或之後添加字段,我需要將它添加到計費字段組中)。
任何幫助表示讚賞!提前致謝!