jQuery(document).ready(function($) {
function applySelect2Fixes() {
// 1. Force the dropdown menu to open safely below the target box to avoid misclicks
if ($.fn.select2) {
$('.select2-container').each(function() {
// Ensure custom positioning rules carry through dynamically
$(this).find('.select2-dropdown').css('margin-top', '4px');
});
}
}
// Run the script on initial page layout load
applySelect2Fixes();
// Re-trigger the exact same fix every single time WooCommerce completes an AJAX filter cycle
$(document).on('ajaxSuccess updated_shop_page fragments_refreshed', function() {
setTimeout(function() {
applySelect2Fixes();
}, 100); // Tiny pause ensures elements are fully drawn by the browser before fixing
});
// Global listener to keep the text search inputs from prematurely dropping focus on click loops
$(document).on('select2:open', function(e) {
$('.select2-search__field').blur();
});
});