Woocommerce 将两个结账字段封装在一个 div 中

我试图将结帐时的帐单状态和帐单国家/地区字段包装在 div 中,但似乎不起作用。这是我的代码:


<div class="woocommerce-billing-fields__field-wrapper">

    <?php

    $fields = $checkout->get_checkout_fields( 'billing' );


    foreach ( $fields as $key => $field ) {

        if($key == 'billing_state'){

            

        } else if($key == 'billing_country'){

            

        } else{

            woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );

        }

    }

    ?>

    <div class="state-province">

        <?php woocommerce_form_field( "billing_state", $checkout->checkout_fields['billing']['billing_state'], $checkout->get_value( 'billing_state' ) ); ?>

        <?php woocommerce_form_field( "billing_country", $checkout->checkout_fields['billing']['billing_country'], $checkout->get_value( 'billing_country' ) ); ?>

    </div>

</div>


不负相思意
浏览 73回答 1
1回答

狐的传说

我找到了一个解决方案,禁用类“form-row”以避免来自 woocommerce 的 js 并添加优先级:function change_woocommerce_field_markup($field, $key, $args, $value) {&nbsp; &nbsp; &nbsp;$field = str_replace('form-row', '', $field);&nbsp; &nbsp; &nbsp;$field = '<div class="single-field-wrapper" data-priority="' . $args['priority'] .&nbsp;&nbsp; &nbsp; &nbsp;'">' . $field . '</div>';&nbsp; &nbsp; &nbsp; if($key === 'billing_state')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$field = '<div class="state-province">'.$field;&nbsp; &nbsp; &nbsp; else if ($key === 'billing_country')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$field = $field.'</div>';&nbsp; &nbsp; &nbsp;return $field;&nbsp; &nbsp;}&nbsp;add_filter("woocommerce_form_field","change_woocommerce_field_markup", 10, 4);这是解释:https://wordpress.stackexchange.com/questions/309700/how-to-hook-on-a-woocommerce-checkout-field/309788
打开App,查看更多内容
随时随地看视频慕课网APP