Skip Navigation

[Resolved] Change number of products per page

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to change number of products per page with WooCommerce view archive page.

Solution:
To change setting number of products with WooCommerce view archive page you can use pre_get_posts hook.

For example:
https://toolset.com/forums/topic/change-number-of-products-per-page/#post-379658

Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by DavidAlexander 7 years, 12 months ago.

Assisted by: Minesh.

Author
Posts
#379400

On a WooCommerce Views Archive Template, how do you set the number of products per page to show? It defaults as 12 but I can't seem to change it and the Woo function

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );

Doesn't seem to effect the loop. Is there a filter I can use to turn 12 into 24?

#379534

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you should try to change number of records to display per page settings if available from your theme?

OR

Just change from normal WP admin:
=> Settings > Reading

#379593

I changed both the Genesis number of posts on blog page and the Settings > Reading screen but neither change the number of posts per page from 12.

Any other ideas?

#379626

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is no other way to accomplish that with Toolset but our developers are planning to add this feature and it will be available in near future. Please note there is no ETA.

#379648

Okay so why does

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 28;' ), 20 );

work but then when toolset is turned on it doesn't? What can I remove from Toolset to make this achievable. If I can't change the number of products on a page (basic requirement) I can't use toolset for WooCommerce anymore.

#379658

Okay I have solved this. So for anyone else here is the function to use if you have problems with number of products with WooCommerce / Toolset / or your Theme.

The below changes it from 12 to 24 successfully on the main shop page, product category archives and product tag archives.

function set_posts_per_page_for_towns_cpt( $query ) {
  if ( is_shop() || is_woocommerce() || is_product_category() || is_product_tag() ) {
    $query->set( 'posts_per_page', '24' );
  }
}
add_action( 'pre_get_posts', 'set_posts_per_page_for_towns_cpt' );

Use the above if the below recommended by WooCommerce doesn't work for you when using Toolset.

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 28;' ), 20 );

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.