第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 WooCommerce 自定義結(jié)帳字段上設(shè)置特定的顯示順序

在 WooCommerce 自定義結(jié)帳字段上設(shè)置特定的顯示順序

PHP
千萬里不及你 2022-01-08 17:43:15
我正在向 woocommerce 結(jié)帳計(jì)費(fèi)部分頁(yè)面添加 20 個(gè)自定義結(jié)帳字段。它以前工作正常。但是最近我們發(fā)現(xiàn)字段的顯示順序已經(jīng)混亂了。我希望有人可以幫助我按照添加的順序顯示自定義字段。我已禁用除 woocommerce 之外的所有插件。我使用的是二十九主題。我刪除了所有自定義字段,然后一次添加一個(gè)。奇怪的是,我能夠添加按順序顯示的 11 個(gè)字段。當(dāng)我們添加 12 個(gè)或更多字段時(shí),顯示混亂。我用一個(gè)簡(jiǎn)單測(cè)試字段的多個(gè)副本替換了所有定制的自定義字段,但問題仍然存在。以下代碼已添加到主題 functions.phpadd_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields',10,3 ); function custom_override_checkout_fields( $fields ) {//unset the unwanted billing fieldsunset($fields['order']['order_comments']);unset($fields['billing']['billing_company']);unset($fields['billing']['billing_address_1']);unset($fields['billing']['billing_address_2']);unset($fields['billing']['billing_city']);unset($fields['billing']['billing_postcode']);unset($fields['billing']['billing_state']);unset($fields['billing']['billing_phone']);//add custom fields$fields['billing']['billing_test1'] = array(    'label'       => __('test1', 'woocommerce'),    'placeholder' => _x('', 'placeholder', 'woocommerce'),    'required'    => true,    'clear'       => true,    'class'     => array('form-row'),    );$fields['billing']['billing_test2'] = array(    'label'       => __('test2', 'woocommerce'),    'placeholder' => _x('', 'placeholder', 'woocommerce'),    'required'    => true,    'clear'       => true,    'class'     => array('form-row'),    );//a further 18 copies of the above field test3->test20 return $fields;}布局應(yīng)該是:-First name    Last nameEmail addresstest1test2 test3....test20實(shí)際布局是:-First nametest10test19test18test17test16test15test14test13test12test11Last nametest9test8test7test6test5test4test3test2test1
查看完整描述

1 回答

?
郎朗坤

TA貢獻(xiàn)1921條經(jīng)驗(yàn) 獲得超9個(gè)贊

您錯(cuò)過了priority允許重新排序表單字段的表單字段“ ”參數(shù)……在下面的代碼中,我使用for循環(huán)動(dòng)態(tài)生成 20 字段(僅用于測(cè)試,因?yàn)樗亲羁斓模?/p>


在這里,這些表單字段的優(yōu)先級(jí)從第一個(gè)的 200 開始,每個(gè)字段增加 10。


代碼:


add_filter( 'woocommerce_checkout_fields', 'customizing_checkout_fields', 10, 1 );

function customizing_checkout_fields( $fields ) {


    ## 1. unset the unwanted billing fields


    unset($fields['order']['order_comments']);

    unset($fields['billing']['billing_company']);

    unset($fields['billing']['billing_address_1']);

    unset($fields['billing']['billing_address_2']);

    unset($fields['billing']['billing_city']);

    unset($fields['billing']['billing_postcode']);

    unset($fields['billing']['billing_state']);

    unset($fields['billing']['billing_phone']);


    ## 2. Add 20 form fields (from "Test 1" to "Test 20")


    // Using a for loop to make the 20 fields dynamically

    for ( $i = 1, $j = 0; $i <= 20; $i++, $j += 10 ) {


        $fields['billing']['billing_test' . $i] = array(

            'label'       => __('Test', 'woocommerce') . ' ' . $i,

            'placeholder' => _x('', 'placeholder', 'woocommerce'),

            'required'    => true,

            'clear'       => true,

            'class'       => array('form-row'),

            'priority'    => (200 + $j) // <== The priority starting at 200 and increasing by 10 each time

        );

    }


    return $fields;

}

代碼位于您的活動(dòng)子主題(或活動(dòng)主題)的 function.php 文件中。測(cè)試和工作。


因此,在您的情況下,您將使用(沒有 for 循環(huán)):


add_filter( 'woocommerce_checkout_fields', 'customizing_checkout_fields', 10, 1 );

function customizing_checkout_fields( $fields ) {


    ## 1. unset the unwanted billing fields


    unset($fields['order']['order_comments']);

    unset($fields['billing']['billing_company']);

    unset($fields['billing']['billing_address_1']);

    unset($fields['billing']['billing_address_2']);

    unset($fields['billing']['billing_city']);

    unset($fields['billing']['billing_postcode']);

    unset($fields['billing']['billing_state']);

    unset($fields['billing']['billing_phone']);


    ## 2. Add 20 form fields (from "Test 1" to "Test 20")


    $fields['billing']['billing_test1'] = array(

        'label'       => __('Test 1', 'woocommerce'),

        'placeholder' => _x('', 'placeholder', 'woocommerce'),

        'required'    => true,

        'clear'       => true,

        'class'       => array('form-row'),

        'priority'    => 200 // <== <== <== priority

    );


    $fields['billing']['billing_test2'] = array(

        'label'       => __('Test 2', 'woocommerce'),

        'placeholder' => _x('', 'placeholder', 'woocommerce'),

        'required'    => true,

        'clear'       => true,

        'class'       => array('form-row'),

        'priority'    => 210 // <== Increased by 10

    );


    // A further 18 copies of the above field from "Test 3" to "Test 20"


    return $fields;

}


查看完整回答
反對(duì) 回復(fù) 2022-01-08
  • 1 回答
  • 0 關(guān)注
  • 137 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)