Reorder Woocommerce checkout fields

后端 未结 5 1206
礼貌的吻别
礼貌的吻别 2020-12-15 00:25

I am trying to reorder the billing fields on the checkout page but everything I tried so far is not working.

Here is the snippet I am currently trying:



        
5条回答
  •  青春惊慌失措
    2020-12-15 00:53

    As @Byeongin correctly mentions in his answer, apart from the backend ordering (that @Frits answer covers) there is also ordering that happens via JavaSrcipt in the front-end when the user selects specific countries from the dropdown menu.

    If you also want to stop this front-end reordering from happening, the best solution I've encountered so far would be to hook into the woocommerce_get_country_locale filter and remove the priority overrides that are added there.

    Something like the following will do the trick (tested with WooCommerce v3.5.4):

    add_filter( 'woocommerce_get_country_locale', function( $locale ) {
        foreach ( $locale as $country_code => $locale_fields ) {
            foreach ( $locale_fields as $field_key => $field_options ) {
                if ( isset( $field_options['priority'] ) ) {
                    unset( $field_options['priority'] );
                }
    
                $locale[ $country_code ][ $field_key ] = $field_options;
            }
        }
    
        return $locale;
    } );
    
    

提交回复
热议问题