woocommerce offtopic - select2 & selectWoo Not Loading Options

admin2025-01-08  3

I created a custom select checkout field and the field works great. When I add a selectWoo or a select2 class to it, it functions like a select2 box but says no results found. The html options are there.

Does select2 or selectWoo not work for a custom field, or did I do something wrong?

Field is:

woocommerce_form_field( 'student_name', array(
    'type'          => 'select',
    'class'         => array('my-field-class form-row-wide ram_select2'),
    'label'         => __('Student'),
    'placeholder'   => __('Student Name'),
    'required'      => true,
    'options'       => $patients,
    ), $checkout->get_value( 'student_name' ));

I initiated the class in an enqueued js script:

(function($) {
$(document).ready(function() {
$('.ram_select2').selectWoo();
});
})(jQuery);

I created a custom select checkout field and the field works great. When I add a selectWoo or a select2 class to it, it functions like a select2 box but says no results found. The html options are there.

Does select2 or selectWoo not work for a custom field, or did I do something wrong?

Field is:

woocommerce_form_field( 'student_name', array(
    'type'          => 'select',
    'class'         => array('my-field-class form-row-wide ram_select2'),
    'label'         => __('Student'),
    'placeholder'   => __('Student Name'),
    'required'      => true,
    'options'       => $patients,
    ), $checkout->get_value( 'student_name' ));

I initiated the class in an enqueued js script:

(function($) {
$(document).ready(function() {
$('.ram_select2').selectWoo();
});
})(jQuery);
Share Improve this question asked Jan 7, 2020 at 20:06 Dan W.Dan W. 234 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Try this way:

woocommerce_form_field( 'student_name', array(
'type'          => 'select',
'class'         => array('my-field-class','form-row-wide','ram_select2'),
'label'         => __('Student'),
'placeholder'   => __('Student Name'),
'required'      => true,
'options'       => $patients,
), $checkout->get_value( 'student_name' ));
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736269214a1334.html

最新回复(0)