An error occurred while fetching products. Please try again later.
'); } }); updateFilterCount(); });/** attribute filter **/ var previousState = ''; var selectedSubcategoryId = null; var isTagFiltered = false; var tagName = 'Customizable'; var currentCategoryId = 259;var selectedSortOption = null;var selectedSortOptionmobile = null; var currentTagName = null; var currentFilters = {}; // Check if the 'customizable' parameter is present in the URL const urlParams = new URLSearchParams(window.location.search); const isCustomizable = urlParams.has('customizable'); if (isCustomizable) { $('#tagToggle').prop('checked', true); isTagFiltered = true; filterProducts(); }if (isCustomizable) { $('#tagToggle-mobile').prop('checked', true); isTagFiltered = true; filterProducts(); } // Toggle customization filter $('#tagToggle').on('change', function() { isTagFiltered = this.checked; previousState = $('.product-list_grids').html(); filterProducts(); });$('#tagToggle-mobile').on('change', function() { isTagFiltered = this.checked; previousState = $('.product-list_grids').html(); filterProducts(); }); // Subcategory filter $(document).on('click', '.catSub-name', function(e) { e.preventDefault(); $('.catSub-name').removeClass('selectedCat'); $(this).addClass('selectedCat'); selectedSubcategoryId = $(this).data('subcategory-id'); filterProducts(); });function scrollToProductList() { var offset = $('.elementor-widget-woocommerce-breadcrumb').offset().top; $('html, body').animate({ scrollTop: offset }, 500);}$('.catSub-name').on('click', function(e) { e.preventDefault(); var subcategoryId = $(this).data('subcategory-id'); var subcategoryName = $(this).data('subcategory-name'); fetchCategoryData(subcategoryId, subcategoryName);scrollToProductList(); }); // Function to fetch category data function fetchCategoryData(subcategoryId, subcategoryName) { var ajaxurl = 'https://www.hotpackglobal.com/wp-admin/admin-ajax.php'; $.ajax({ type: 'POST', url: ajaxurl, data: { action: 'fetch_category_data', subcategory_id: subcategoryId }, success: function(response) { if (response.success) {var attributeCount = $('#productGrid .card').length;// $('#productCount').text(response.data.product_count + ' Results for ' + subcategoryName);// $('.count-display').text(attributeCount + ' Results '); } else { console.error('Failed to fetch category data'); } }, error: function(xhr, status, error) { console.error('AJAX Error:', error); } }); } // Attribute filter $(document).on('click', '.product-list_nav-list .dropdown-menu a.dropdown-item', function(e) { e.preventDefault(); var attribute_slug = $(this).closest('.nav-item.dropdown').find('.nav-link').data('bs-target'); var term_slug = $(this).data('bs-target'); var attribute_name = $(this).text(); // Check if the term is already selected if (!$(`li[data-attribute-slug="${attribute_slug}"][data-term-slug="${term_slug}"]`).length) { const newLiElement = `An error occurred while fetching products. Please try again later.
'); } }); }, error: function(xhr, status, error) { $productGrid.html('An error occurred while fetching filtered product count. Please try again later.
'); } }); }, error: function(xhr, status, error) { $productGrid.html('An error occurred while fetching category data. Please try again later.
'); } }); }, error: function(xhr, status, error) { $productGrid.html('An error occurred while fetching category name. Please try again later.
'); } });}function fetchAttributes(categoryId) { var ajaxurl = 'https://www.hotpackglobal.com/wp-admin/admin-ajax.php';$('#attributeList').html(''); $.ajax({ type: 'POST', url: ajaxurl, data: { action: 'fetch_category_attributes', category_id: categoryId }, success: function(attributeResponse) { $('#attributeList').html(attributeResponse); }, error: function(xhr, status, error) { $('#attributeList').html('An error occurred while fetching attributes. Please try again later.
'); } });}// Event listener for pagination links$(document).on('click', '.pagination.custom-pages a', function(e) { e.preventDefault(); var pageNumber = $(this).attr('href').split('page/')[1]; var filters = collectFilters(); var categoryId = selectedSubcategoryId || currentCategoryId; fetchProducts(categoryId, isTagFiltered ? tagName : null, filters, selectedSortOption, pageNumber);});});/** clear button **/document.getElementById('clearAllBtn').addEventListener('click', function() { location.reload();});jQuery(document).ready(function($) { $('input[name="sortOption"]').change(function() { $('label').css('color', ''); if ($(this).is(':checked')) { $(this).closest('label').css('color', '#000000'); } });});