在Woocommerce的管理订单页面上添加城市下拉列表 [英] Add a drop down list of cities on admin orders pages in Woocommerce

查看:248
本文介绍了在Woocommerce的管理订单页面上添加城市下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to add drop down list of cities to new order page in woocommerce, I know way to add this functionality to checkout page, but here I want to add this functionality to admin new order pages in Woocommerce.

请参阅示例图片以供参考:

See example image for reference:

推荐答案

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

Use the following hooked function for admin new order (where you will set your array of cities):

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文件)。经过测试并有效。

Code goes in function.php file of your active child theme (or active theme). Tested and works.


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

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


这篇关于在Woocommerce的管理订单页面上添加城市下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆