2015-11-07 95 views
0

PHP我已經重新排序,並改變了與此WooCommerce結帳領域:簡化了woocommerce結賬

//Reorder checkout fields 
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_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_email']  = $fields['billing']['billing_email']; 
    $fields2['billing']['billing_phone']  = $fields['billing']['billing_phone']; 
    $fields2['billing']['billing_country'] = $fields['billing']['billing_country']; 

    $fields2['shipping']['shipping_first_name'] = $fields['shipping']['shipping_first_name']; 
    $fields2['shipping']['shipping_last_name'] = $fields['shipping']['shipping_last_name']; 
    $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']; 
    $fields2['order']['order_comments'] = $fields['order']['order_comments']; 
    $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; 
} 

有沒有一種方法來組合使用和/或簡化這個?它工作得很好,但看起來如此漫長和複雜。

+0

也許你要問這一項上http://codereview.stackexchange.com? – Terminus

回答

1

這樣的事情呢?

add_filter("woocommerce_checkout_fields", "reorder_woo_fields"); 

function reorder_woo_fields($fields) { 

    $billing_order = array(
     "billing_first_name", 
     "billing_last_name", 
     "billing_address_1", 
     "billing_city", 
     "billing_postcode", 
     "billing_email", 
     "billing_phone", 
     "billing_country" 
    ); 
    foreach($billing_order as $field) 
    { 
     $billing_fields[$field] = $fields["billing"][$field]; 
    } 

    $shipping_order = array(
     "shipping_first_name", 
     "shipping_last_name", 
     "shipping_address_1", 
     "shipping_city", 
     "shipping_postcode", 
     "shipping_country", 
    ); 
    foreach($shipping_order as $field) 
    { 
     $shipping_fields[$field] = $fields["shipping"][$field]; 
    } 


    $fields["billing"] = $billing_fields; 
    $fields["shipping"] = $shipping_fields; 

    return $fields; 
} 

編輯:

add_filter('woocommerce_billing_fields', 'add_custom_css_on_checkout', 10, 1); 
function add_custom_css_on_checkout($address_fields) { 
    $address_fields['billing_first_name']['class'] = 'form-row-wide'; 
    $address_fields['billing_last_name']['class'] = 'form-row-wide'; 
    return $address_fields; 
} 
+0

但是這不包括使名字和姓氏完整寬度的功能... –

+0

嘗試編輯並添加其他字段,我想你只需要數組中的類參數。 –

+0

沒有得到這個工作... –