• Resolved klivie

    (@klivie)


    I’m doing some work on loading the sidebar widgets of the category pages with AJAX (Mainly because we’ve done some bench marking tests and worked out the Filtering by Attributes widgets are causing a major slow in the page loading times of category landing pages).

    Anyway, I was wondering how the Filter by Attribute Widgets pull the current term slug from the current wp_query.

    Initial problems I had were the current object didn’t exist because we were obviously going through the ajax url, I’ve managed to fix that by passing in the taxonomy name, and current term slug to execute a new WP_Query. This gives me all the correct post results and finds the correct filters & counts.

    But the slugs are the only thing incorrect, the links for the attributes are replacing the current term slug with the base shop slug. e.g. The link “/product-category/lighting/pendant-lights/?filter_colour=black” is instead using “/shop/?filter_colour=black”

    I believe the problem is because the ajax calls believes the current page is the “shop” page instead of a “category” page but I’m not sure which arguments of the wp_query object the widget uses to work this out

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Riaan K.

    (@riaanknoetze)

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the following places for more development-oriented questions:
    * WooCommerce Slack Community: https://woocommerce.com/community-slack/
    * Advanced WooCommerce group on Facebook: https://www.facebook.com/groups/advanced.woocommerce/

    Hello

    How did you do the ajax request?

    If it was done manually, can you share the ajax request function? maybe in private message, if you want to keep it private.
    Without looking at the code maybe try sending the current page to ajax as a parameter(or category id) and use it in the code written.

    Thank you

    Thread Starter klivie

    (@klivie)

    I have some progress on this.

    I’ve worked out if I send the current product-category slug to the request then I get the correct slug names.

    e.g.
    $wp_query = new WP_Query;
    $wp_query->query( array(‘product_cat’ => ‘category-slug’));

    Although this does mean that the filters I get shown are for all products. E.g. the counts for “black” colour is 924 rather than 50. because it’s finding all products within the SHOP with that cat. not all products within the CATEGORY.

    It also doesn’t yet have the ability to pass through the existing query string. So a maximum of 1 filter can be applied at the moment.

    I may very well delve into your WooCommerce Slack Community for some help as I’ve already got a slack account set up so thanks for the resource!

    Plugin Support John Coy a11n

    (@johndcoy)

    Automattic Happiness Engineer

    Hi @klivie

    Anytime! I’ll resolve this thread but you are welcome to open a new thread if you have any questions in the future.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Ajax Sidebar Query’ is closed to new replies.