因此,我有一個使用woocommerce的電子商務,我使用自定義運費來支付運費。 而且我已經添加了新的輸入數據(選擇)。就像你可以看到下面的圖片: WordPress的Woocommerce從定製運輸領域(AJAX)獲得價值
// Hook in
add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields');
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields($fields) {
$fields['billing']['billing_city'] = array(
'type' => 'select',
'label' => __('Kota/Kabupaten', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide', 'address-field'),
'clear' => true,
'options' => array(
'' => 'Pilih Kota/Kabupaten'
)
);
$fields['shipping']['shipping_city'] = array(
'type' => 'select',
'label' => __('Kota/Kabupaten', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide', 'address-field'),
'clear' => true,
'options' => array(
'' => 'Pilih Kota/Kabupaten'
)
);
$fields['billing']['billing_subdistrict'] = array(
'type' => 'select',
'label' => __('Kecamatan', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide', 'address-field'),
'clear' => true,
'options' => array(
'' => 'Pilih Kecamatan'
)
);
$fields['shipping']['shipping_subdistrict'] = array(
'type' => 'select',
'label' => __('Kecamatan', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide', 'address-field'),
'clear' => true,
'options' => array(
'' => 'Pilih Kecamatan'
)
);
return $fields;
}
Woocommerce默認數據有ADDRESS_1,address_2,國家,州,城市,但我需要一個名爲街道一個更多的數據。我不需要保存這些數據(subdistrict)。但我需要使用該值作爲跟蹤運費的參數。
我已經創建了新的class-custom-shipping-delivery.php。 和我已經確保該功能完美工作,因爲我已經嘗試手動設置$子區域數據。
//custom-shipping.php
$province = $package['destination']['state'];
$city = $package['destination']['city'];
$subdistrict= 'something';
//How to get the data from custom field (ajax)
//because I need to see the shipping fee result before Checkout (and update it to add rate)
$destination_code = $this->getDestinationCode($province,$city,$subdistrict);
$ongkir = $this->cek_ongkir($origin,$destination_code,$weight);
//print_r();
// send the final rate to the user.
$this->add_rate(array(
'id' => $this->id,
'label' => $this->title,
'cost' => $ongkir
));
摘要:
如何從街辦輸入類型選擇(結賬頁)值?
對不起,我只是從另一個人的工作編輯,所以我不明白,代碼。但我認爲他們忘了獲得這個價值,因爲他們只是硬編碼,我是一個新手,所以我不知道如何通過結算表單傳遞數據。
後代碼,而不是屏幕截圖 – Blueblazer172