How do I get woocommerce product listing to show all products in one page?

I have the following category within a site:
http://rivetnuttool.com/site/product-category/blue-pneumatic-rivet-nut-tools/
And I want it to show all of the 7 products within the first page, and even if I have 100 products to show them in one single page.
I have tried with different solutions like adding this to my functions.php file:
add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return -1;’ ) );

Rewriting the shortcode like the solution proposed here http://ideas.woothemes.com/forums/133476-woocommerce/suggestions/4146798-add-pagination-support-for-list-of-products-render

Read More

And several other online options, and none of them seems to work, I allways get the pagination and the limit.

The theme used in the site is Divi.

Related posts

4 comments

  1. Just add the conditional check to your functions.php file:

    if( isset( $_GET['showall'] ) )
    {
        add_filter( 'loop_shop_per_page', create_function( '$cols', 'return -1;' ) );
    }
    else
    {
        add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ) );
    }
    
  2. loop_shop_per_page is the correct filter. If you aren’t seeing any effect, then add a later priority. In my test case my parent theme was filtering loop_shop_per_page so my child theme’s filter wasn’t doing anything.

    add_filter( 'loop_shop_per_page', 'so_31843880_show_all_products', 20 );
    function so_31843880_show_all_products(){
        return -1;
    }
    

    To apply the filter to only product categories you would add some conditional logic:

    add_filter( 'loop_shop_per_page', 'so_show_all_products' );
    function so_31843880_show_all_products($per_page){
        if( is_taxonomy('product_cat') ){
            $per_page = -1;
        }
        return $per_page;
    }
    
  3. I corrected and changed the custom code from the above blog post to:

    function shortcode_settori( $atts ) {
                global $woocommerce_loop;
    
                extract( shortcode_atts( array(
                        'per_page' => '24',
                        'columns' => '4',
                        'orderby' => 'title',
                        'order' => 'desc',
                        'settore' => '', // Slugs
                        'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
                ), $atts ) );
                if ( ! $settore ) {
                        return '';
                }
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                // Default ordering args
                $ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order );
    
                $args = array(
            'post_type'             => 'product',
            'post_status'           => 'publish',
            'ignore_sticky_posts'   => 1,
            'posts_per_page'        => '999',
            'meta_query'            => array(
                array(
                    'key'           => '_visibility',
                    'value'         => array('catalog', 'visible'),
                    'compare'       => 'IN'
                )
            ),
            'tax_query'             => array(
                array(
                    'taxonomy'      => 'product_cat',
                    'field' => 'term_id', //This is optional, as it defaults to 'term_id'
                    'terms'         => $settore,
                    'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
                )
            )
                );
                $products = new WP_Query($args);
    
                $woocommerce_loop['columns'] = $columns;
                if ( $products->have_posts() ) : ?>
                        <?php woocommerce_product_loop_start(); ?>
                        <?php while ( $products->have_posts() ) : $products->the_post(); ?>
                                <?php wc_get_template_part( 'content', 'product' ); ?>
                        <?php endwhile; // end of the loop. ?>
                        <?php woocommerce_product_loop_end(); ?>
    
                <?php endif;
                if($products->max_num_pages>1){
                ?>
                <nav class="woocommerce-pagination">
                    <?php
                    echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
                        'base' => esc_url( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ),
                        'format' => '',
                        'current' => max( 1, get_query_var( 'paged' ) ),
                        'total' => $products->max_num_pages,
                        'prev_text' => '&larr;',
                        'next_text' => '&rarr;',
                        'type' => 'list',
                        'end_size' => 3,
                        'mid_size' => 3
                        ) ) );
                        ?>
                </nav>
    
        <?php }
        woocommerce_reset_loop();
        wp_reset_postdata();
        echo $return;
        $return = '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
        // Remove ordering query arguments
        WC()->query->remove_ordering_args();
    
        return $return;
    }
    
    add_shortcode( 'prodotti_per_settore', 'shortcode_settori' );
    

    And everything works now.

  4. Now, in 2019, I just adjust a parameter in a Customize panel by:
    Apperance>Customize>WooCommerce Options>Shop Archive sidebar layout>total products per page
    Then, fill the number I want into that.

Comments are closed.