Storefront Filters example: Change the number of products displayed per page

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a WooExpert or DeveloperĀ for assistance. We are unable to provide support for customizations under ourĀ  Support Policy.
Storefront has a lotĀ of filters (go here for an overview). These allow you to change the output of how things are displayed in the theme. For example, you could want to change the shop page template to only display 8 products instead of the default 12.

Create a function

ā†‘ Back to top
First, we need to create a function. We can call it whatever we want so here we’ll opt for alter_sf_products_per_page ().Ā Since we want to change the default 12 to 8, that is what we need to add: return 8;.

Find the right hook

ā†‘ Back to top
Second, find the right place (or hook) to add this filter to. In the Storefront filters reference guide, the hook we find is storefront_products_per_page.

Add a filter

ā†‘ Back to top
Finally, we need to add a filter that adds the created function to the right hook.
function alter_sf_products_per_page() {
// Return the number of products per page ( default: 12 ).
return 8;
}
add_filter('storefront_products_per_page', 'alter_sf_products_per_page' );
Weā€™ll need let our theme to know to use the code. In order to do that,Ā  you can paste the snippet in the functions.php file of your child theme. The result will be the following:
Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.