重新排列(按优先级排序)Woocommerce我的帐户领域

问题描述 投票:1回答:1

我怎样才能重新安排。我想以后my-accountbilling_address_1领域找到billing_statebilling_city领域。

我用woocommerce_form_field_args挂钩,然后用switch找到每一个arg

function bcod_wc_form_field_args( $args, $key, $value ){
switch ($key) {
        case 'billing_country':
            $args['class'] = array('hidden');
            break;
        case 'billing_address_1' :
            $args['priority'] = '85';// push down this field to bottom of state and city 
            $args['label'] = $args['label'] . ' Priority : ' . $args['priority'];
            $args['placeholder'] = 'خیابان اصلی ، خیابان فرعی ، کوچه ، پلاک';
            break;
        case 'billing_state' :
            $args['priority'] = '50';
            $args['label'] = $args['label'] . ' Priority : ' . $args['priority'];
            $args['class'] = array('form-row-first');
            break;
        case 'billing_city' :
            $args['priority'] = '55';
            $args['label'] = $args['label'] . ' Priority : ' . $args['priority'];
            $args['class'] = array('form-row-last');
            break;
        case 'billing_postcode' :
            $args['label'] = $args['label'] . ' Priority : ' . $args['priority'];
            $args['priority'] = '190';
            $args['class'] = array('form-row-first');
            break;
        case 'billing_email' :
            $args['label'] = $args['label'] . ' Priority : ' . $args['priority'];
            $args['priority'] = '80';
            $args['class'] = array('form-row-last');
            break;
        default:
            return $args;
            break;
        }
    return $args;
}

我希望位于billing_address_1statecity领域,但这些代码不会影响排序字段。优先级改变,但这些字段是在默认地方。这个形象是我的结果:

wordpress plugins woocommerce hook-woocommerce account
1个回答
1
投票

要重新排列“我的帐户”不会忽略结算领域,你需要使用这样的:

// Change billing fields location
add_filter( 'woocommerce_billing_fields', 'arrange_billing_fields', 10, 1 );
function arrange_billing_fields( $fields ){
    // Only on my account
    if( is_account_page() ) :

    $fields['billing_country']['class']         = array('hidden');

    $fields['billing_state']['priority']        = '50';
    $fields['billing_state']['label']          .= ' (Priority : '.$fields['billing_state']['priority'].')';
    $fields['billing_state']['class']           = array('form-row-first');

    $fields['billing_city']['priority']         = '55';
    $fields['billing_city']['label']           .= ' (Priority : '.$fields['billing_city']['priority'].')';
    $fields['billing_city']['class']            = array('form-row-last');

    $fields['billing_email']['priority']        = '80';
    $fields['billing_email']['label']          .= ' (Priority : '.$fields['billing_email']['priority'].')';
    $fields['billing_email']['class']           = array('form-row-last');

    $fields['billing_address_1']['priority']    = '85';
    $fields['billing_address_1']['label']      .= ' (Priority : '.$fields['billing_address_1']['priority'].')';
    $fields['billing_address_1']['placeholder'] = 'خیابان اصلی ، خیابان فرعی ، کوچه ، پلاک';

    $fields['billing_postcode']['priority']     = '190';
    $fields['billing_postcode']['label']       .= ' (Priority : '.$fields['billing_postcode']['priority'].')';
    $fields['billing_postcode']['class']        = array('form-row-first');

    endif;

    return $fields;
}

// For the state field priority location for some countries
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
function custom_country_locale( $countries_locale ){
    // Only on my account
    if( is_account_page() ):

    // Loop Through country locale array
    foreach( $countries_locale as $country_code => $fields ){
        // Loop through defined fields (targeting the state field)
        foreach( $fields as $field_key => $data ) {
            if( $field_key == 'state' && isset($data['priority']) ){
                $countries_locale[$country_code][$field_key]['priority'] = '50';
            }
        }
    }

    endif;

    return $countries_locale;
}

代码放在您的活动子主题的function.php文件(或活动主题)。测试和工程。

© www.soinside.com 2019 - 2024. All rights reserved.