将自定义字段添加到运输区域表单 - Woocommerce

时间:2018-04-11 06:23:24

标签: php wordpress woocommerce hook-woocommerce

我正在尝试在创建新的送货区域时将选择字段添加到Woocommerce 送货标签和送货区域部分。在搜索解决方案时,我在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获取设置的方法。

显然,我在这里做错了,可能会挂钩错误的过滤器或其他任何东西。请帮忙。

0 个答案:

没有答案