我在选择框中获得所有运输区域和固定费率组合的费用。但是当选择框更改值时,运费不起作用。
我在主题的文件功能中编写所有代码。这是我的代码:
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'vtnShipping' );
function vtnShipping( $fields ) {
$delivery_zones = WC_Shipping_Zones::get_zones();
$vtnData['name'] = [];
$vtnData['value'] = [];
$vtnResults = [];
foreach ( (array) $delivery_zones as $key => $the_zone ) {
$vtnKhuVuc = $the_zone['zone_name'];
$vtnTien = ($the_zone['zone_locations'][0]->type == 'postcode') ? $the_zone['zone_locations'][0]->code : $the_zone['zone_locations'][1]->code;
array_push($vtnData['name'], $vtnKhuVuc);
array_push($vtnData['value'], $vtnTien);
}
// Only
foreach ($vtnData['value'] as $key => $value) {
$vtnResults[$value] = $vtnData['name'][$key];
}
$fields['billing']['billing_postcode'] = array(
'type' => 'select',
'class' => array('billing_postcode'),
'id' => 'billing_postcode',
'label' => __('Nơi vận chuyển'),
'required' => true,
'options' => $vtnResults
);
return $fields;
}
谢谢!