그래서 저는 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를 만듭니다. 그리고 이미 $ subdistrict 데이터를 수동으로 설정하려고하기 때문에 함수가 완벽하게 작동하는지 확인합니다.
//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
));
요약 :
하는 방법 (체크 아웃 페이지)를 선택 가도 입력 형식에서 값을 얻는 방법?
죄송합니다. 저는 다른 사람의 작업을 편집하여 코드를 전혀 이해하지 못합니다. 하지만 그들은 단지 하드 코드를하기 때문에 그 가치를 잊어 버린 것 같아요. 그리고 저는 Wordpress의 초보자이기 때문에 계산 양식에 데이터를 전달하는 법을 모르겠습니다.
우편 번호 대신을 screenshots – Blueblazer172