• Hello, i’m using woocommerce and i have an issue:

    Our client wants a Carousel which shows filtered product results. The filters are attributes and price.

    What he wants is
    1 – to show ALL the results (no paginated) in the carousel/slider
    2 – Show all the paginated results of the filter in a pagination (or infinite scroll) grid.

    Both in the same page.

    What i’ve done >

    In the Archive-product.php:

    <?php if ( have_posts() ) : ?>
    
        <?php do_action( 'woocommerce_archive_description' ); ?>
    
           <?php if (is_product_category ('koi-2')): ?>
    
              <div class="carru"> 
    
                  <section class="regular slider">
                  <?php obtener_kois(); ?>
                  </section>
    
              </div>
    
        <hr>
    
          <?php endif;?>
    
                <?php woocommerce_product_loop_start(); ?>
                <?php woocommerce_product_subcategories(); ?>
                <?php while ( have_posts() ) : the_post(); ?>
                    <!-- Product Item -->
                    <?php wc_get_template( 'content-product.php', array('_delay' => $_delay, 'wrapper' => 'li') ); ?>
                    <!-- End Product Item -->
                    <?php  $_delay+=200; ?>
                <?php endwhile;?>
            <?php woocommerce_product_loop_end(); ?>
            <div class="row filters-container-down">
                <!-- Pagination -->
                <?php do_action( 'woocommerce_after_shop_loop' );?>
                <!-- End Pagination -->

    Then, in functions.php:

    function  obtener_kois($min_price,$max_price,$atrib1,$atrib2)
    
    {
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    $args = array(
                    'post_type'             => 'product',
                    'post_status'           => 'publish',
                    'ignore_sticky_posts'   => 1,
                    'posts_per_page'        => -1,
                    'product_cat'           => 'category-product-slug',
                    'meta_query'            => array(
                        array(
                            'key'           => '_price',
                             'value' => array($min_price, $max_price),
                             'compare' => 'BETWEEN',
                             'type' => 'NUMERIC'
                        )
                    ),
                    'tax_query'             => array(
                            'relation' => 'AND',
                        array(
                            'taxonomy'      => 'pa_' . 'attribute-1',
                            'terms'         => explode( ',', $atrib1 ),
                            'field'         => 'term_id',
                            'operator'      => 'IN'
                        ),
                        array(
                            'taxonomy'      => 'pa_' . 'attribute-2',
                            'terms'         => explode( ',', $atrib2 ),
                            'field'         => 'term_id',
                            'operator'      => 'IN'
                        ),
                    )
                );

    I could make it work filtering by price and one of the attributes, but not for both attributes and price.

    Do you have any idea where the problem is?

    Thanks in advance!!

    https://ww.wp.xz.cn/plugins/woocommerce/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Given the code above, are you aware the products would need to match all cases? i.e. have ALL atributes you define, and also match the price rule.

    Thread Starter Gonzaloklever

    (@gonzaloklever)

    Hello Mike, You mean by the ‘AND’ Relation?

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Yes. So you are showing products with atrib1 AND atrib2 AND the price in your range.

    Thread Starter Gonzaloklever

    (@gonzaloklever)

    Yes, Exactly.
    And if no attribute is filtering, then it must show all the results.

    Thanks!

    Plugin Contributor Mike Jolley

    (@mikejolley)

    > And if no attribute is filtering, then it must show all the results.

    You don’t have a case for that in your code.

    Thread Starter Gonzaloklever

    (@gonzaloklever)

    My issue is more about the filter than showing all the no filtered results, I will solve this later.

    The point is that when i filter for one attribute (e.g. atrib1), it doesnt show the results but when we use 2 filters (atrib1 and atrib2) it makes an AND filter. I attach 2 screenshots:

    1: you can see the filtered results for atribute 1 (SEXO) and attribute 2 (VARIEDAD) in different colors.
    When i use both filters, it makes an AND relation (which is ok as we have it configured by now) . When i only use 1 filter, the var_dump returns the values but it is not shown in the carousel (Screenshot 2)

    SCREENSHOT 1 http://i.imgur.com/C80phWOt.png
    SCREENSHOT 2 http://i.imgur.com/vwsUBNv.png

    Do i need to add something to make the filter array work?

    function  obtener_kois($min_price,$max_price,$variedad,$sexo)
    
    {
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
     $args = array(
                    'post_type'             => 'product',
                    'post_status'           => 'publish',
                    'ignore_sticky_posts'   => 1,
                    'posts_per_page'        => -1,
                    'product_cat'           => 'koi-2',
    
                   'tax_query' => array(
                    'relation' => 'AND',
        array(
          'taxonomy' => 'pa_' . 'variedad-koi',
          'field'    => 'term_id',
          'terms'     => explode( ',', $variedad ),
        ),
        array(
          'taxonomy' => 'pa_' . 'koi-sexo',
          'field'    => 'term_id',
          'terms'     => explode( ',', $sexo ),
        ),
    
       ),
    );
    
       var_dump($sexo);
       var_dump($variedad);
       var_dump($min_price);
       var_dump($max_price);
    Thread Starter Gonzaloklever

    (@gonzaloklever)

    Sorry, here the correct screenshots

    http://i.imgur.com/C80phWO.png

    View post on imgur.com

    Plugin Contributor Mike Jolley

    (@mikejolley)

    It’s going to be really difficult to understand the issue here without debugging myself which I cannot really do. Since you opened this issue we did launch 2.6.1 which fixed some count issues on category pages. Maybe that will help.

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

The topic ‘Dynamic Product Carousel’ is closed to new replies.