[英]How do I add validation to custom select boxes in WooCommerce Checkout page and apply select2 styling.
[英]WooCommerce - How to add only custom countries to select on checkout page and keep autocomplete feature?
我必須在結帳頁面的選擇框中僅顯示允許的運輸國家。 我使用以下代碼添加了自定義列表,但它破壞了自動填充功能,並保留了正常選擇(屏幕截圖上的紅色邊框)。
如何僅添加自定義國家/地區並保留自動填充功能?
function woo_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_country'] = array(
'type' => 'select',
'required'=>true,
'label' => __('Country', 'shop'),
'options' => getAllowedCountries()
);
$fields['billing']['billing_country'] = array(
'type' => 'select',
'required'=>true,
'label' => __('Country', 'shop'),
'options' => getAllowedCountries()
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'woo_override_checkout_fields' );
我已經解決了,解決方案很簡單:
$(document).ready(function() {
$("#billing_country,#shipping_country").select2();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.