私は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と呼ばれる1以上のデータを必要としています。私はそのデータを保存する必要はありません(下位)。しかし、私はトラックの運賃のためのパラメータとしてその値を使用する必要があります。
私はすでに新しい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
));
概要:(チェックアウトページ上)を選択Subdistrict入力タイプから値を取得する方法
?
申し訳ありません私は他の人の仕事から編集するだけで、私はそのコードを全く理解できません。しかし、私は彼らがそれをハードコードし、私はワードプレスの初心者ですので、チェックアウトフォームにデータを渡す方法を知らないので、彼らはその価値を得るのを忘れたと思います。
ポストコードの代わりに、 screenshots – Blueblazer172