多选在实例设置模式中无法正确显示 - Woocommerce

问题描述 投票:0回答:1

我为 Woocommerce 创建了一种自定义送货方式,支持

shipping-zones
instance-settings
instance-settings-modal
。实例设置的表单字段是使用 Woocommerce 的Settings API 创建的,如下所示:

$settings = array(
    'title' => array(
        'title'         => __( 'Method title', 'woocommerce' ),
        'type'          => 'text',
        'description'   => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
        'default'       => __( 'Flat rate', 'woocommerce' ),
        'desc_tip'      => true,
    ),
    'tax_status' => array(
        'title'         => __( 'Tax status', 'woocommerce' ),
        'type'          => 'select',
        'class'         => 'wc-enhanced-select',
        'default'       => 'taxable',
        'options'       => array(
            'taxable'   => __( 'Taxable', 'woocommerce' ),
            'none'      => _x( 'None', 'Tax status', 'woocommerce' ),
        ),
    ),
    'cities' => array(
        'title'         => __( 'Cities', 'woocommerce' ),
        'type'          => 'multiselect',
        'description'   => __( 'Select all cities within current zone to which this shipping method applies.', 'woocommerce' ),
        'desc_tip'      => true,
        'class'         => 'wc-enhanced-select',
        'options'       => $zone_cities,
    ),
    'cost' => array(
        'title'         => __( 'Cost', 'woocommerce' ),
        'type'          => 'text',
        'placeholder'   => '',
        'description'   => $cost_desc,
        'default'       => '0',
        'desc_tip'      => true,
    ),
);

一切工作正常,除了

cities
的多选字段无法正常工作。它显示为具有多个属性的普通选择。这是屏幕截图:

虽然,当我仅使用

instance-settings
时,多选也可以正常工作。这是另一个屏幕截图:

同样的问题已在 GitHub here 上关闭。感谢任何帮助找到根本问题的帮助。

更新: 如果您将

tax_status
字段类型从
multiselect
更改为
select
,则可以在 Woocommerce 核心的统一费率运输方法中重现该问题。

woocommerce/includes/shipping/flat-rate/includes/settings-flat-rate.php
的第22行更改如下:

$settings = array(
    'title' => array(
        'title'         => __( 'Method title', 'woocommerce' ),
        'type'          => 'text',
        'description'   => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
        'default'       => __( 'Flat rate', 'woocommerce' ),
        'desc_tip'      => true,
    ),
    'tax_status' => array(
        'title'         => __( 'Tax status', 'woocommerce' ),
        'type'          => 'multiselect', // *** Change here ***
        'class'         => 'wc-enhanced-select',
        'default'       => 'taxable',
        'options'       => array(
            'taxable'   => __( 'Taxable', 'woocommerce' ),
            'none'      => _x( 'None', 'Tax status', 'woocommerce' ),
        ),
    ),
    'cost' => array(
        'title'         => __( 'Cost', 'woocommerce' ),
        'type'          => 'text',
        'placeholder'   => '',
        'description'   => $cost_desc,
        'default'       => '0',
        'desc_tip'      => true,
    ),
);
php wordpress woocommerce multi-select
1个回答
0
投票

不确定这对你来说意味着什么——5年后。但唯一可靠的方法就是像这样监视 WCBackboneModal。

jQuery(($) => {
    $(document.body).on('wc_backbone_modal_loaded', (evt, tgt) => {
        if (tgt !== 'wc-modal-shipping-method-settings') {
            return;
        }
        $(document.body).trigger('wc-enhanced-select-init');
    });
});
© www.soinside.com 2019 - 2024. All rights reserved.