jQuery(document).ready(function ($) { $('#meatbox-filter-form').on('submit', function (e) { e.preventDefault(); const weightGroup = $(this).find('[name="weight_group"]').val(); const dateFrom = $(this).find('[name="date_from"]').val(); const dateTo = $(this).find('[name="date_to"]').val(); const hideSold = $(this).find('[name="hide_sold"]').is(':checked'); const hideExpired = $(this).find('[name="hide_expired"]').is(':checked'); $('#meatbox-table tbody tr').each(function () { const row = $(this); const weight = parseFloat(row.data('weight')); const sold = row.data('sold') == '1'; const expired = row.data('expired') == '1'; let show = true; // 🏋️ Weight filter if (weightGroup === 'lt3' && weight >= 3) show = false; if (weightGroup === '3to5' && (weight < 3 || weight > 5)) show = false; if (weightGroup === '5to7' && (weight < 5 || weight > 7)) show = false; if (weightGroup === '7plus' && weight <= 7) show = false; // 📅 Date filter if (dateFrom) { const fromTimestamp = new Date(dateFrom).getTime(); const createdDate = new Date(row.data('date')).getTime(); if (createdDate < fromTimestamp) show = false; } if (dateTo) { const toTimestamp = new Date(dateTo).getTime(); const createdDate = new Date(row.data('date')).getTime(); if (createdDate > toTimestamp) show = false; } // ❌ Sold/Expired toggle if (hideSold && sold) show = false; if (hideExpired && expired) show = false; row.toggle(show); }); }); });