【问题标题】:Add a drop down list of cities on admin orders pages in Woocommerce在 Woocommerce 的管理订单页面上添加城市下拉列表
【发布时间】:2019-02-23 03:36:29
【问题描述】:

我想在 woocommerce 的新订单页面中添加城市下拉列表,我知道如何将此功能添加到结帐页面,但在这里我想添加此功能管理新订单页面 在 Woocommerce 中。

参见示例图片以供参考:

【问题讨论】:

    标签: php wordpress woocommerce admin orders


    【解决方案1】:

    使用以下钩子函数管理新订单(您将在其中设置城市数组)

    add_filter( 'woocommerce_admin_billing_fields' , 'admin_billing_city_select_field' );
    function admin_billing_city_select_field( $fields ) {
        global $pagenow;
        
        // Only for new order creation
        if( $pagenow != 'post-new.php' ) return $fields;
    
        $fields['city'] = array(
            'label'   => __( 'City', 'woocommerce' ),
            'show'    => false,
            'class'   => 'js_field-city select short',
            'type'    => 'select',
            'options' => array(
                ''              => __( 'Select a city…', 'woocommerce' ),
                'Los Angeles'   => __( 'Los Angeles', 'woocommerce' ),
                'San Antonio'   => __( 'San Antonio', 'woocommerce' ),
            ),
        );
    
        return $fields;
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

    如果您希望它也适用于管理员编辑订单页面,您将删除以下行:

    if( $pagenow != 'post-new.php' ) return $fields;
    

    【讨论】:

      猜你喜欢
      • 2018-04-11
      • 2020-08-12
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 2018-09-09
      • 2021-01-13
      相关资源
      最近更新 更多