Forums Forums Search & Filter Pro Can filter product categories too?

Viewing 10 posts - 21 through 30 (of 33 total)
  • Trevor
    #257357
    This reply has been marked as private.
    Anonymous
    #257368
    This reply has been marked as private.
    Trevor
    #257471

    Your results structure is wrong. Can you give me a copy of the template for that page (upload it to a file sharing site like weshare, dropbox, google drive, etc.), but don’t post it here?

    Anonymous
    #257475
    This reply has been marked as private.
    Trevor
    #257636

    Here is the modified template code (copy it from the forum post, not the email, as email software will change some characters).

    What did I change?

    On line 78 is where I moved the form output to. I commented out the line where it had been – line 104. If this new code works, you can remove line 104.

    Line 80 is commented out (in HTML – again if this works, remove this line):

    <li class="product">

    and added back in at line 109 as an echo, and the ending </li> added in at line 123 also as an echo, and the original end </li> now on line 128 is commented out (can also remove).

    Try this code then:

    <?php
    /**
     * The Template for displaying product archives, including the main shop page which is a post type archive
     *
     * This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
     *
     * HOWEVER, on occasion WooCommerce will need to update template files and you
     * (the theme developer) will need to copy the new files to your theme to
     * maintain compatibility. We try to do this as little as possible, but it does
     * happen. When this occurs the version of the template file will be bumped and
     * the readme will list any important changes.
     *
     * @see https://docs.woocommerce.com/document/template-structure/
     * @package WooCommerce/Templates
     * @version 3.4.0
     */
    
    defined( 'ABSPATH' ) || exit;
    
    get_header( 'shop' ); ?>
    
    <?php
    
    /**
     * Hook: woocommerce_before_main_content.
     *
     * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
     * @hooked woocommerce_breadcrumb - 20
     * @hooked WC_Structured_Data::generate_website_data() - 30
     */
    do_action( 'woocommerce_before_main_content' );
    
    ?>
    <header class="woocommerce-products-header">
            <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
                    <h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>
            <?php endif; ?>
    
            <?php
            /**
             * Hook: woocommerce_archive_description.
             *
             * @hooked woocommerce_taxonomy_archive_description - 10
             * @hooked woocommerce_product_archive_description - 10
             */
            do_action( 'woocommerce_archive_description' );
            ?>
    </header>
    
    <?php
    
    if ( woocommerce_product_loop() ) {
    
            /**
             * Hook: woocommerce_before_shop_loop.
             *
             * @hooked woocommerce_output_all_notices - 10
             * @hooked woocommerce_result_count - 20
             * @hooked woocommerce_catalog_ordering - 30
             */
            do_action( 'woocommerce_before_shop_loop' ); ?>
    
    echo do_shortcode('[searchandfilter id="3791"]');
            <ul class="wpf-search-container products">
    <!--        <li class="product"> -->
            <?php
    
    // Get The queried object ( a WP_Term or a WP_Post Object)
    $term = get_queried_object();
    
    // To be sure that is a WP_Term Object to avoid errors
    if( is_a($term, 'WP_Term') ) :
    
    // Setup your custom query
    $loop = new WP_Query( array(
        'post_type'      => 'product',
        'posts_per_page' => -1,
        'post_status'    => 'publish',
        'tax_query'      => array( array(
            'taxonomy' => 'product_cat', // The taxonomy name
            'field'    => 'term_id', // Type of field ('term_id', 'slug', 'name' or 'term_taxonomy_id')
            'terms'    => $term->term_id, // can be an integer, a string or an array
        ) ),
    ) );
            
    //echo do_shortcode('[searchandfilter id="3791"]');
    
    if ( $loop->have_posts() ) :
    while ( $loop->have_posts() ) : $loop->the_post();
    echo '<li class="product">';
    the_post_thumbnail( 'thumbnail');
    echo '<div style="margin:8px;">';
    echo 'movie preview - ';
    the_title();
    echo "<br>";
    $price = get_regular_or_sale_price();
            echo $price;
            echo '&nbsp';
    $regularpriceifsale = get_regular_price_if_sale();
            echo $regularpriceifsale;
    echo '<br>';
    echo '<br>';
    echo '</div>';
    echo '</li>';
    endwhile;
    wp_reset_postdata(); // Remember to reset
    endif; endif;
    ?>
    <!--                </li> -->
    </ul>
    <?php
    
            /**
             * Hook: woocommerce_after_shop_loop.
             *
             * @hooked woocommerce_pagination - 10
             */
            do_action( 'woocommerce_after_shop_loop' );
    } else {
            /**
             * Hook: woocommerce_no_products_found.
             *
             * @hooked wc_no_products_found - 10
             */
            do_action( 'woocommerce_no_products_found' );
    }
    
    /**
     * Hook: woocommerce_after_main_content.
     *
     * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
     */
    do_action( 'woocommerce_after_main_content' );
    
    /**
     * Hook: woocommerce_sidebar.
     *
     * @hooked woocommerce_get_sidebar - 10
     */
    do_action( 'woocommerce_sidebar' );
    ?>
    
    <?php get_footer(); ?>
    Anonymous
    #257794
    This reply has been marked as private.
    Trevor
    #257922
    This reply has been marked as private.
    Anonymous
    #258439

    I hope you had a great holiday Trevor. My apologies now, I have also been backlogged with work. Fortunately, the weekend is around the corner!

    Thank you for this code, it works so that I can filter by tags now 🙂 . Only issue I’m facing now is with the filter and pagination.

    For example on this page, if I filter by tag “tag two”, the filter works, but also shows a page “2” that can be clicked on. Clicking on page “2” shows products outside of the filter. Do you know why this could be now?

    Have a lovely weekend~

    Trevor
    #258507

    I see that the Pagination Container setting in the form is set to:

    .pagination a

    Can you try setting that to:

    .woocommerce-pagination a

    Anonymous
    #258561
    This reply has been marked as private.
Viewing 10 posts - 21 through 30 (of 33 total)