Add a drop down list of cities on admin orders pages in Woocommerce

末鹿安然 提交于 2019-12-11 04:11:48

问题


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:


回答1:


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;
}

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

If you want it to work also for admin edit order pages, you will remove the following line:

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



来源:https://stackoverflow.com/questions/52397761/add-a-drop-down-list-of-cities-on-admin-orders-pages-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!