我为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
时,multiselect也能正常工作。这是另一个截图:
同样的问题在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,
),
);