WooCommerce is the most popular eCommerce platform on the internet – it powers over 28% off all online stores. Today, we are going to cover how to implement WooCommerce infinite scrolling with the free Ajax Load More plugin for WordPress.

Before we begin, make sure you have both Ajax Load More and WooCommerce activated and products have been created so there is content ready to infinite scroll 🙂

Note: The following guide and examples reference code from the official WooCommerce theme, Storefront.

Implementation

There are essentially four steps to WooCommerce infinite scrolling with Ajax Load More. None of the steps are overly difficult to complete, but you will be required to make modifications to core WooCommerce templates during the process.

The implementation steps are as follows:

  1. Create Child Theme
  2. Create Repeater Template
  3. Building a Shortcode
  4. WooCommerce Template

Alright, let’s go!


Create Child Theme

Since this tutorial will require modifying core theme template files the first step will be to create a child theme – this will allow us to make modifications and not worry about conflicts when theme updates are applied.

There are many resources available online that explain exactly how to create a child theme so I won’t go into anymore detail on how to do that today.


Create Repeater Template

Next, you’ll want to create a unique WooCommerce Repeater Template for displaying your products,

Most WooCommerce compatible themes use a variation of default content-product.php template while iterating over products so you may be fine by simply copying the following template into your Ajax Load More Repeater Template.

Note: The template above was copied directly from WooCommerce core – I recommend inspecting your theme in case it’s using a modified version of this template.
/plugins/woocommerce/templates/content-product.php


Building a Shortcode

After creating your Repeater Template you will need to build a custom WooCommerce shortcode – this shortcode instructs Ajax Load More on what content to include in the infinite scroll query.

Shop Home/Landing Page

For a shop home or landing page you simply need to set product as the Post Type and include products as a custom css_classes parameter.

Product Archives

For displaying product category and tag archives you will also be required to pass in the current taxonomy (product_tag / product_cat) and taxonomy term to the Ajax Load More shortcode.

Note: The css_classes shortcode parameter may differ depending on your theme.


WooCommerce Template

The final step is to clone and modify the archive-product.php template from /plugins/woocommerce/templates/ to the root of your current theme directory. This template used for displaying WooCommerce products so modifying this file directly will allow you to place the Ajax Load More shortcode into the correct location.

Pro Tip: Your theme may already be using custom WooCommerce templates – in that case you should modify those templates and not core WooCommerce templates as referenced below.

Once the template has been cloned, open the file in your code editor and select everything from the opening if(have_posts()) to the closing endif; conditional statement. You will want to replace the selected contents with the following Ajax Load More specific code.

Click here to view the complete archive-product.php template.

With the template updated and steps 1 thru 4 complete you should have a working WooCommerce infinite scroll – check out the following links to see our code implemented on a shop homepage and product archive.

Wrapping Things Up

It might seem like a lot of tasks to implement WooCommerce infinite scrolling, but keep in mind at the end of the day all you’re really doing is replacing the default WooCommerce loop with Ajax Load More.

Got any WooCommerce specific questions or suggestions? Leave them in the comments and I’ll do my best to help you out!

Comments

It's your lucky day! You could be the first to comment on Infinite Scroll WooCommerce Products with Ajax Load More.

Leave a Reply

Your email address will not be published. Required fields are marked *