我正在结帐页面中为结算部分创建自定义字段,我在源代码中看到data-priority
属性,但我不知道如何将我的字段移至Primary Name
& Last Name
我的结算表
Chrome开发工具上显示的代码
简单来说,我需要将该字段移到顶部。
答案 0 :(得分:1)
WooCommerce在没有太多文档的情况下增加了优先级(仅来自WC 3)。 您需要添加到functions.php
add_filter("woocommerce_checkout_fields", "order_fields", 30);
function order_fields($fields) {
$fields["billing"]["user_rut"]["priority"] = 30;
return $fields;
}
您可能还需要使用old order method [可能只是优先考虑,不重新排序不起作用的字段]
答案 1 :(得分:0)
使用以下程序。 对于woocommerce greter然后版本3
add_filter( 'woocommerce_default_address_fields', 'mrks_woocommerce_default_address_fields' );
function mrks_woocommerce_default_address_fields( $fields ) {
// default priorities:
// 'first_name' - 10
// 'last_name' - 20
// 'company' - 30
// 'country' - 40
// 'address_1' - 50
// 'address_2' - 60
// 'city' - 70
// 'state' - 80
// 'postcode' - 90
// e.g. move 'company' above 'first_name':
// just assign priority less than 10
$fields['state']['priority'] = 41;
return $fields;
}
对于低于版本3的woocommerce
add_filter( 'woocommerce_checkout_fields', 'mrks_move_checkout_fields' );
function mrks_move_checkout_fields( $fields ) {
// Billing: move these around in the order you'd like
$fields2['billing']['billing_first_name'] = $fields['billing']['billing_first_name'];
$fields2['billing']['billing_last_name'] = $fields['billing']['billing_last_name'];
$fields2['billing']['billing_company'] = $fields['billing']['billing_company'];
$fields2['billing']['billing_address_1'] = $fields['billing']['billing_address_1'];
$fields2['billing']['billing_address_2'] = $fields['billing']['billing_address_2'];
$fields2['billing']['billing_city'] = $fields['billing']['billing_city'];
$fields2['billing']['billing_postcode'] = $fields['billing']['billing_postcode'];
$fields2['billing']['billing_state'] = $fields['billing']['billing_state'];
$fields2['billing']['billing_country'] = $fields['billing']['billing_country'];
$fields2['billing']['billing_email'] = $fields['billing']['billing_email'];
$fields2['billing']['billing_phone'] = $fields['billing']['billing_phone'];
// Shipping: move these around in the order you'd like
$fields2['shipping']['shipping_first_name'] = $fields['shipping']['shipping_first_name'];
$fields2['shipping']['shipping_last_name'] = $fields['shipping']['shipping_last_name'];
$fields2['shipping']['shipping_company'] = $fields['shipping']['shipping_company'];
$fields2['shipping']['shipping_address_1'] = $fields['shipping']['shipping_address_1'];
$fields2['shipping']['shipping_address_2'] = $fields['shipping']['shipping_address_2'];
$fields2['shipping']['shipping_city'] = $fields['shipping']['shipping_city'];
$fields2['shipping']['shipping_postcode'] = $fields['shipping']['shipping_postcode'];
$fields2['shipping']['shipping_state'] = $fields['shipping']['shipping_state'];
$fields2['shipping']['shipping_country'] = $fields['shipping']['shipping_country'];
$checkout_fields = array_merge( $fields, $fields2);
return $checkout_fields;
}
答案 2 :(得分:0)
尝试一下:
function custom_field( $fields ) {
$fields['billing']['RUT'] = array(
'priority' => 20 //or the number on position you what
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_field');