【问题标题】:Change the order of admin billing address fields in WooCommerce orders更改 WooCommerce 订单中管理员帐单地址字段的顺序
【发布时间】:2020-02-11 15:52:31
【问题描述】:

我在管理员中遇到了 woocommerce 订单问题,我希望在页面末尾显示 billing_address_2,如下所示。

谁能帮帮我。

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce orders


    【解决方案1】:

    负责显示该字段的核心文件位于 WooCommerce 插件中:includes/admin/meta-boxes/class-wc-meta-box-order-data.php

    唯一可用且高效的钩子是:woocommerce_admin_shipping_fields

    但您只能使用以下方式更改管理计费字段顺序:

    add_filter( 'woocommerce_admin_billing_fields' , 'change_order_admin_billing_fields' );
    function change_order_admin_billing_fields( $fields ) {
        global $the_order;
    
        $address_2 = $fields['address_2'];
    
        unset($fields['address_2']);
    
        $fields['address_2'] = $address_2;
    
        return $fields;
    }
    

    这会给你类似的东西:

    如您所见,您不会按照您的意愿在交易 ID 之后显示帐单 address_2 字段,而只会在帐单 phone 字段下显示。


    添加 - 在 billing_country 字段之前显示 billing_address_2 字段

    add_filter( 'woocommerce_admin_billing_fields' , 'change_order_admin_billing_fields' );
    function change_order_admin_billing_fields( $fields ) {
        global $the_order;
    
        $sorted_fields = [];
        $address_2 = $fields['address_2'];
        unset($fields['address_2']);
    
        foreach ( $fields as $key => $values ) {
            if( $key === 'country' ) {
                $sorted_fields['address_2'] = $address_2;
            }
            $sorted_fields[$key] = $values;
        }
    
        return $sorted_fields;
    }
    

    【讨论】:

    • 是的,非常感谢,我的问题解决了,我还能在国家字段之前显示 billing_address_2 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 2016-08-18
    • 2016-12-08
    • 2021-11-10
    • 2018-09-05
    • 1970-01-01
    • 2020-12-09
    相关资源
    最近更新 更多