Jason, we found away to do it using SELECT2
https://github.com/select2/select2
From include folder find the file “view-functions.php” and because the CSS has conflict with the admin CSS so the CSS should be added before the theme CSS files so in line 5259 we add
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
Select2 needs jquery to be loaded before the library so it has to loaded after jquery in line 8459
We need to add the query .js file after select2
So we make a file and added from the admin panel:
JS file contains
$( document ).ready(function() {
const element_60 = $("#element_60");
const element_44 = $("#element_44");
element_60.select2({
minimumInputLength: 3,
ajax: {
dataType: "json",
url:'http://www.xxxxxxx.com/get_styles.php',
},}).on('select2:select', function (e) {
const data = e.params.data;
$("#element_6").val(data.id);
$("#element_7").val(data.size);
$("#element_30").val(data.brand);
$("#element_28").val(data.color);
});
element_44.select2({
minimumInputLength: 3,
ajax: {
dataType: "json",
url:'http://www.xxxxx.com/get_styles.php',
},}).on('select2:select', function (e) {
const data = e.params.data;
$("#element_13").val(data.id);
$("#element_14").val(data.size);
$("#element_27").val(data.color);
});
});
The element numbers comes from admin panel and where we add the dropdown the ID would be used,
In order to make a Ajax call for select 2 we need to make a small json api (get_styles.php)
<?php
header('Content-Type: application/json');
$q = $_GET['q'];
if ( !$db = mysqli_connect("localhost", "xxx", "xxx", "xxx") )
die( "can not connect to database");
$query = "
SELECT DISTINCT style as id
, CONCAT(style
,'-',Brand
,'-', size
,'-',color
) as text
, rand, color, size FROM Products
WHERE style LIKE '%{$q}%' AND ID != ''
";
if ( !$results = $db->query($query) )
die($query );
$data=[];
while ($row = $results->fetch_array()) {
$data[]= $row;
}
echo json_encode(["results"=>$data]).
This will provide json data for the select2
To check the conflict, we will need to go to admin panel and change the theme color if it is working it means we have no conflict but if it’s not changing then it means we need to change the CSS location to higher position in the view_functions.php
hope it helps, the javascript above I couldn't get to work and I needed to find another solution