繁体   English   中英

WooCommerce 可搜索下拉列表

[英]WooCommerce searchable drop down list

所以我用一些自定义字段实现了一个计费表单,我的下拉菜单是:

$fields['billing_complex_name'] = array(
         'label' => __('Complex Name', 'woocommerce'), // Add custom field label
        'placeholder' => _x('E.g Raslouw Gardens', 'placeholder', 'woocommerce'), // Add custom field placeholder
        'required' => false, // if field is required or not
        'clear' => false, // add clear or not
        'type' => 'select',// add field type
          'options'     => array(
         '' => 'Please select',
                         'ansaarestate'=> 'Ansaar Estate',
              'bangladeshheights'=> 'Bangladesh Heights',
                        'celticmanor'=> 'Celtic Manor',
                        'chantelplace'=> 'Chantel Place',
             ... 
        'class' => array('my-css'),
          'priority' => 51,// 
   );

然后使用 jQuery 我实施以下更改:

jQuery(document).ready(function(){
    // Your code in here
  jQuery(document).on('input','#billing_complex_name', function() {
 
      myFunc();
})
function myFunc() {
    // your function code
//var phone_num = jQuery('#billing_phone').val(<?php $phone_number ?>);

    
var complex_name = jQuery('#billing_complex_name').val();

var suburb = jQuery('#billing_suburb').val();

if (complex_name == 'eldogleneast') {
   jQuery("#billing_suburb").val('ELD');
   jQuery('#billing_postcode').val('0157');
    jQuery("#billing_complex_address").val('');
jQuery("#billing_postcode").prop("readonly", false);

当然,这取决于复杂条件的选择,例如邮政编码或郊区等。我现在的问题是:我需要使下拉列表可搜索并有一个其他选择,如果选择了其他我需要一个文本输入用户输入,这将是选定的值(所有 jQuery 将不会对邮政编码或任何内容进行任何更改)

使用 select2.js 库来实现它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM