我已使用此功能在Woocommerce结帐页面上重新排列了订单字段:
//Reorder checkout
add_filter( 'woocommerce_checkout_fields', 'reorder_woo_fields' );
function reorder_woo_fields( $fields ) {
$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_city'] = $fields['billing']['billing_city'];
$fields2['billing']['billing_postcode'] = $fields['billing']['billing_postcode'];
$fields2['billing']['billing_country'] = $fields['billing']['billing_country'];
$fields2['billing']['billing_email'] = $fields['billing']['billing_email'];
$fields2['billing']['billing_phone'] = $fields['billing']['billing_phone'];
$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_city'] = $fields['shipping']['shipping_city'];
$fields2['shipping']['shipping_postcode'] = $fields['shipping']['shipping_postcode'];
$fields2['shipping']['shipping_country'] = $fields['shipping']['shipping_country'];
// Add full width Classes and Clears to Adjustments
$fields2['billing']['billing_first_name'] = array(
'label' => __('First Name', 'woocommerce'),
'class' => array('form-row-wide'),
'clear' => true,
'required' => true
);
$fields2['billing']['billing_last_name'] = array(
'label' => __('Last Name', 'woocommerce'),
'class' => array('form-row-wide'),
'clear' => true,
'required' => true
);
$fields2['shipping']['shipping_first_name'] = array(
'label' => __('First Name', 'woocommerce'),
'class' => array('form-row-wide'),
'clear' => true,
'required' => true
);
$fields2['shipping']['shipping_last_name'] = array(
'label' => __('Last Name', 'woocommerce'),
'class' => array('form-row-wide'),
'clear' => true,
'required' => true
);
return $fields2;
}
这是有效的,但是当启用调试模式时,我在chekcout页面上收到错误:注意:未定义的索引:在/html/wordpress/wp-content/plugins/woocommerce/templates/checkout/form-shipping.php中的订单在线58
警告:在第58行的/html/wordpress/wp-content/plugins/woocommerce/templates/checkout/form-shipping.php中为foreach()提供的参数无效
aynone可以理解这个吗?
2 回答
您可以尝试以下代码重新排序结帐页面字段 . 您可以选择数组中字段的顺序 .
您可以在the WooCommerce docs找到有关该指南的完整指南 .
您正在定义一个新数组
$fields2
,并且此数组没有woocommerce_checkout_fields
中所需的所有字段 . 您只需要像@pallavi showed you一样覆盖$fields["billing"]
和$fields["shipping"]
.要删除字段(例如order_comments),您可以将此行放在您的函数中