HUSKY - WooCommerce Product Filter Professional

WooCommerce AJAX Filter Breaks Product Grid Layout: Causes and Fixes

The shop looks right until the first filter click. Then three columns become four, rows get holes, product cards lose the theme's badges or buttons, or the sidebar slides under the products. When a WooCommerce AJAX filter breaks the product grid layout, the products themselves are correct; what changed is the HTML that draws them. Below is what HUSKY's AJAX mode replaces, why theme-specific markup gets lost on the way, and the fix for each symptom.

What AJAX mode replaces, and what it cannot copy

With Try to ajaxify the shop set to Yes (WooCommerce → Settings → Products Filter → Options), the plugin marks out the product area of the shop and category pages. On the woocommerce_before_shop_loop hook (priority 2) it opens a container <div class="woocommerce woocommerce-page woof_shortcode_output"> with <div id="woof_results_by_ajax"> inside it, and on woocommerce_after_shop_loop (priority 10) it closes both.

When a visitor changes the filter, the script sends a request to /wp-admin/admin-ajax.php with the action woof_draw_products. The server renders [woof_products is_ajax=1] and the script swaps the container for the result. That result is built from standard WooCommerce parts only:

  • the woocommerce_before_shop_loop hook (notices, result count, sorting drop-down);
  • woocommerce_product_loop_start(), which prints <ul class="products columns-N">;
  • the content-product.php template part for each product;
  • woocommerce_product_loop_end() and the woocommerce_after_shop_loop hook (pagination).

Two things follow from this. First, anything your theme's archive template prints between the two hooks by itself (extra wrappers, a grid class, a builder's loop skin) is not in the new HTML. Second, the new HTML is produced in an admin-ajax request, not on the shop page. Code that runs while the shop page loads, on the wp or template_redirect action, inside the archive template or only when is_admin() is false, never runs for it. Theme scripts that styled the grid once on page load do not run again either.

Find out what changed: compare the markup before and after

Open the shop in a private window, right-click the first product and choose Inspect. Note the classes on ul.products, on its parent elements and on the first li.product. Apply a filter and inspect the same place again. The difference points to the fix:

Symptom after filteringCauseSection
Different number of columns, columns-4 instead of columns-3The theme's column setting is not applied in the AJAX requestColumns and gaps
Rows of 3, then 1, then 3; holes in the gridThe first/last row classes are counted for another column numberColumns and gaps
Sidebar or footer moves, disappears or repeats; products shown twiceThe theme does not call both shop-loop hooks around the loopShop-loop hooks
Class missing on ul.products, buttons or badges back, grid/list view lost, blank imagesTheme markup, PHP conditions or theme scriptsTheme card features

Product columns change after filtering, and gaps appear

[woof_products] takes its column number from WooCommerce's loop_shop_columns filter, which falls back to Products per row in Appearance → Customize → WooCommerce → Product Catalog. Themes with their own column option often apply it only while a shop page loads. In the AJAX request that code does not run, so the results come back with WooCommerce's value: often 4 where the shop shows 3.

The gaps have the same root. WooCommerce gives the first product of each row the class first and the last one last, counted from that column number, and the classic float grid starts a new row at every first. If the theme's CSS fits 3 products per row and the AJAX HTML counts 4, every fourth product forces a new row: 3 products, then 1 alone, then 3 again.

Set the column number once, for every request, with the number your shop shows on desktop:

/**
 * Same number of columns on shop pages and in HUSKY AJAX results.
 * Child theme functions.php or a code snippets plugin.
 */
add_filter( 'loop_shop_columns', function () {
    return 3; // products per row on desktop
}, 999 );

Do not wrap it in is_shop() or similar checks, or it will be skipped in the AJAX request. Priority 999 makes it win over the theme's own filter. The short FAQ force filtered results into a set number of columns uses the same filter. On a custom page, [woof_products columns=3] sets the number directly. Phones and tablets are styled by the theme's CSS media queries in both cases.

If the class reads columns-3 after filtering and the widths are still wrong, the theme sizes products through a class on its own wrapper outside the swapped area. Add CSS for the AJAX container in Appearance → Customize → Additional CSS or in the plugin's Custom CSS code field (Advanced → Code):

/* HUSKY AJAX results: 3 products per row in a float-based grid */
#woof_results_by_ajax ul.products li.product {
    width: 30.75%;
    margin-right: 3.8%;
    clear: none;
}
#woof_results_by_ajax ul.products li.product:nth-child(3n) {
    margin-right: 0;
}
#woof_results_by_ajax ul.products li.product:nth-child(3n+1) {
    clear: both;
}

If your theme lays out ul.products with CSS grid instead of floats, one rule is enough: #woof_results_by_ajax ul.products { grid-template-columns: repeat(3, 1fr); }. Wrap either version in a desktop media query if the theme uses fewer columns on phones.

Sidebar below the products, broken footer, double results: the shop-loop hooks

AJAX mode needs the theme to call woocommerce_before_shop_loop directly before the product list and woocommerce_after_shop_loop directly after it, as the standard WooCommerce template does. When it does not:

  • The closing hook is missing. The two containers are never closed, and the browser closes them only at the end of their parent element. The sidebar, the second column or the footer end up inside the product area: often the sidebar sits under the products already on page load, and after the first filter click everything inside the container, the sidebar with the filter included, is replaced by the results.
  • The hooks are called somewhere else. If the theme fires them in a toolbar and prints the product loop after woocommerce_after_shop_loop, the AJAX results land in the container while the original grid stays below it, so products appear twice.
  • Theme wrappers cross the containers. An element the theme opens on woocommerce_before_shop_loop and closes on woocommerce_after_shop_loop must sit entirely inside HUSKY's containers (opened after priority 2, closed before priority 10) or entirely outside them. Anything in between overlaps them and breaks the nesting.

To check, open the page source (Ctrl+U), search for woof_results_by_ajax and follow the HTML down: after the closing </ul> of the products and the pagination there must be two </div> before the sidebar or footer starts. In the theme folder, search the archive templates for woocommerce_after_shop_loop. The product part of a template that works with AJAX mode looks like WooCommerce's own archive-product.php:

<?php
if ( woocommerce_product_loop() ) {
    do_action( 'woocommerce_before_shop_loop' );

    woocommerce_product_loop_start();
    if ( wc_get_loop_prop( 'total' ) ) {
        while ( have_posts() ) {
            the_post();
            do_action( 'woocommerce_shop_loop' );
            wc_get_template_part( 'content', 'product' );
        }
    }
    woocommerce_product_loop_end();

    do_action( 'woocommerce_after_shop_loop' );
} else {
    do_action( 'woocommerce_no_products_found' );
}

Make the change in a child theme copy of the template, or ask the theme author to add the missing hook. Page builder layouts rarely call both hooks; for them redirect mode, described below, is the realistic choice. Products that do not change at all are covered in filter URL changes but products do not change, and Elementor templates in Elementor Loop Grid and archive templates not filtering.

Theme card features lost: badges, buttons, grid classes, scripts

Changes your PHP makes only on shop pages

Code that hides add-to-cart buttons, adds a category line or a badge, and decides that on wp or template_redirect with is_shop(), does not run in the AJAX request, so the default card comes back after filtering. Run it for HUSKY's request too. admin_init fires in every admin-ajax request:

/**
 * Card changes for shop pages AND for HUSKY AJAX results.
 * Child theme functions.php or a code snippets plugin.
 */
function my_shop_card_changes() {
    // Example: no add-to-cart buttons in the product grid
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}

// Normal page loads of the shop and product archives
add_action( 'wp', function () {
    if ( is_shop() || is_product_taxonomy() ) {
        my_shop_card_changes();
    }
} );

// HUSKY AJAX filtering, sent through admin-ajax.php
add_action( 'admin_init', function () {
    if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && 'woof_draw_products' === $_REQUEST['action'] ) {
        my_shop_card_changes();
    }
} );

Theme options that change the card (a category line, a hover image, a quick view button) are often applied the same way inside the theme. If they disappear after filtering and the theme has no hook that also covers AJAX requests, use redirect mode.

Classes the theme adds to the product list

If the comparison shows a class on ul.products that exists on page load and is missing after filtering, add it to the AJAX response with the woof_draw_products_html filter. It receives the HTML that is about to be sent to the browser:

/**
 * Add the theme's grid class to the product list in HUSKY AJAX results.
 * Child theme functions.php or a code snippets plugin.
 */
add_filter( 'woof_draw_products_html', function ( $html, $shortcode_str ) {
    return str_replace(
        '<ul class="products columns-',
        '<ul class="products my-theme-grid columns-', // use the class from your page
        $html
    );
}, 10, 2 );

The search string matches WooCommerce's own loop/loop-start.php; if your theme overrides that file, copy the opening tag from the page source. When the theme renders cards with a template part other than content-product.php, return its name with the woof_template_part filter: the value product-grid loads content-product-grid.php from your theme's woocommerce folder.

Theme scripts: lazy images, equal heights, masonry, quick view

Scripts that run once on page load (lazy-loaded images, equal-height cards, masonry, grid/list switchers, quick view buttons) do not see the new products. HUSKY triggers the jQuery event woof_ajax_done after every swap; put the theme's initialisation call there, in a theme JS file or in JavaScript code after AJAX is done (Advanced → Code). The theme author can name the function; more on the event in woof_ajax_done.

jQuery(document).on('woof_ajax_done', function () {
    // Many layout scripts recalculate on resize
    jQuery(window).trigger('resize');
    // Call your theme's own init function here if it has one
});

Result count or sorting shown twice

A theme that prints its own count and sorting bar outside the product area can still get WooCommerce's default copies inside the AJAX results. Hide the inner copies, only if they really are duplicates:

#woof_results_by_ajax .woocommerce-result-count,
#woof_results_by_ajax .woocommerce-ordering {
    display: none;
}

If the theme's own count outside the area does not update after filtering, put its CSS selector into Result count css selector (Advanced → Options): the plugin then sends a fresh count with every AJAX response and replaces the element it finds.

When to give up AJAX: redirect mode and Turbo mode

Some layouts cannot be rebuilt from standard WooCommerce parts: builder loop skins, carousels, theme templates without the hooks. Set Try to ajaxify the shop to No. Each filter change then loads the filtered URL and your theme renders the whole page as usual, so the grid is identical to the unfiltered shop. What you lose is the in-place update. To reload once per search instead of after every click, set Autosubmit to No so the filter waits for its button, and see auto-scroll to products in redirect mode to land the visitor on the results.

If Try to ajaxify the shop jumps back to Yes, Turbo mode is on: it switches AJAX mode on at every page load. Set Enable turbo mode to No in its tab first, then switch AJAX off, and purge the page cache so visitors get the new setting.

Checklist

  • Markup compared before and after filtering in the browser inspector.
  • loop_shop_columns returns the shop's column number without page conditions.
  • Page source shows the two HUSKY containers closing right after the products and pagination.
  • Card changes in PHP also run for the woof_draw_products request; theme scripts re-run on woof_ajax_done.
  • If the layout still differs: Try to ajaxify the shop = No, with Turbo mode off and caches purged.

If the layout still breaks with a default theme such as Storefront and only HUSKY active, open a topic on the HUSKY support forum with a link to the shop page and a description of what changes after filtering.