• Resolved lockoloop

    (@lockoloop)


    Hi,
    So I have this custom archive page where I display all products per category, with a navbar of the categories on the side that is supposed to scroll to the category (anchors).
    However, it seems not all the products are being loaded from the start, because clicking on the last category sends me only halfway through the page.
    In my example, clicking on Teas & Coffees will only send you to Spices & Herbs.
    Is there a way to solve that?
    Here’s my code:

    echo '<ul class="woocommerce">';
    			
    			$categories_args = array( 'taxonomy' => 'product_cat' );
    			$product_categories = get_terms( $categories_args );
    			
    			foreach ($product_categories as $product_category) {
    				$term_id 	= $product_category->term_id; // Term ID
    				$term_name 	= $product_category->name; // Term name
    				$term_desc 	= $product_category->description; // Term description
    				$term_link 	= get_term_link($product_category->slug, $product_category->taxonomy); 
    
    				echo '<li class="cat-title" id="cat-'.$term_id.'">'; // for each term we will create one list element
    				echo '<h3>'.$term_name.'</h3>';
    				
    				$products_args = array(
    					'post_type' => 		'product', // we want to get products
    					'orderby' => 		'title',
    					'order' => 			'ASC',
    					'limit' => 			-1,
    					'posts_per_page' => -1,
    					'paginate'          => false,
    					'page'              => 1,
    					'tax_query' 		=> array( 
    						array(
    							'taxonomy' => 'product_cat',
    							'field'    => 'term_id',
    							'terms'    => $term_id,
    						),
    					),
    				);
    				$products = new WP_Query( $products_args );
    
    				if ( $products->have_posts() ) { 
    					woocommerce_product_loop_start();
    
    					while ( $products->have_posts() ) : $products->the_post();
    						wc_get_template_part( 'content', 'product' );
    					endwhile;
    
    					woocommerce_product_loop_end();
    					wp_reset_postdata();
    
    				} else {
    					do_action('woocommerce_no_products_found');
    					}
    				
    				echo '</li>';
    			}
    			echo '</ul>';

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to load all products on the shop page?’ is closed to new replies.