jQuery(document).ready(function($){
function loadProducts(){
const category=$('#etw-category').val();
const min_price=$('#etw-min-price').val();
const max_price=$('#etw-max-price').val();
const orderby=$('#etw-orderby').val();
$.ajax({
url: etw_ajax.url,
type: 'POST',
data: {
action: 'etw_filter_products',
nonce: etw_ajax.nonce,
category: category,
min_price: min_price,
max_price: max_price,
orderby: orderby
},
beforeSend: function(){
$('#etw-products').html('<div class="etw-loader">Loading...</div>');
},
success: function(response){
$('#etw-products').html(response);
}});
}
loadProducts();
$('#etw-category, #etw-min-price, #etw-max-price, #etw-orderby').on('change input', function (){
loadProducts();
});
});