我正在尝试添加一个选择字段到Woocommerce Shipping选项卡和它的Shipping Zones部分,同时创建一个新的运输区域 . 在搜索解决方案时,我在Woocommerce的官方文档中找到了this .

到目前为止我尝试过的是:

// Fires on 'plugins_loaded' action of WordPress
public function plugins_loaded_action() {
    add_filter( 'woocommerce_get_settings_shipping', array( $this, 'shipping_zone_settings_add_city_field' ), 10, 2 );
}

public function shipping_zone_settings_add_city_field( $settings, $current_section ) {

    echo 'this runs only for shipping_options section';

    /**
     * Check the current section for shipping zone
     */
    if( $current_section === 'shipping_zones' ) {
        // Add city field to settings
        $settings[] = array(
            array( 
                'name' => __( 'Zone City', 'woocommerce' ),
                'type' => 'title',
                'desc' => __( 'Specify city names for current shipping region', 'woocommerce' ),
                'id' => 'shipping_zones',
            ),
            array(
                'name' => __( 'Zone Cities', 'woocommerce' ),
                'desc_tip' => __( 'Add all cities you want to be apply this shipping region for.', 'woocommerce' ),
                'id' => 'wc_shipping_zone_cities',
                'type' => 'multiselect',
                'desc' => __( 'Cities for this shipping region', 'woocommerce' ),
            ),
            array(
                'type' => 'sectionend',
                'id' => 'shipping_zones',
            ),
        );
    }
    return $settings;
}

但是钩子滤波器函数只运行 shipping_options 部分,因为我只能在该部分的顶部看到 echo 输出 .
用于送货设置的Woocommerce类具有this获取设置的方法 .

很明显,我在这里做错了,可能会挂钩不正确的过滤器或其他任何东西 . 请帮忙 .