Add pagination support for list of products rendered by shortcodes like product_category
When using a shortcode like
[productcategory category="" perpage="12" columns="4" orderby="date" order="desc"]
to display products, only a fixed number of products appear as set by 'per_page' attribute and there's no way to see the remaining ones. Currently the only way is to set that to a big number like say, 500 to show all the products - which is not an ideal solution.
It will be really helpful to have pagination for the products list rendered by WooCommerce shortcodes.
Requests from other users for the same in the past:
Archives should be used for proper pagination. Shortcodes are for static output – adding pagination for this kills the ability to use static caching, requires extra queries and can hurt performance.
Extensions can add pagination if desired, or custom shortcodes can be made (and based on the core ones).
Queen Eve commented
I tried to use this solution here
but I donot understand how to do it :(
anyone can help please?
After all this time, this is still isn't an option? I thought I just couldn't figure out how to "turn it on" but it doesn't exist? Crazy.
Two Swans Shoppe commented
I second this request.
The shortcodes are very handy because there are limitations with the built-in woocommerce pages to display your product. For example, I may want to customize the display by adding a designer's logo and additional information about the products such as care and shipping.
It's all well and good that there are coding hacks out there to get this to work, but I'm trying to run an e-Commerce store. I need to spend my time on growing my business and adding valuable content as easily as possible. I don't want to waste my time on "playing web developer".
here is a solution that really worked for me:
The thing is, you have to use wp_query instead of the shortcode.
Add this code to your custom page template or any other place you want to use the shortcode. It gets the current pagination page:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
Then, you'll have to find the function that generate the shortcode you want to use.
All shortcode functions are located at "woocommerce/includes/class-wc-shortcodes.php."
Copy that function to your page template.
Add a new global var '$customWooQuery', like this:
global $woocommerce_loop, $customWooQuery;
Add a parameter like this to your wp_query
'paged' => $paged,
Your wp_query has to be like this:
$customWooQuery = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
Now, your pagination.php have to be like this:
global $wp_query, $customWooQuery;
$finalQuery = $wp_query;
$finalQuery = $customWooQuery;
if ( $finalQuery->max_num_pages <= 1 )
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
'base' => str_replace( 999999999, '%#%', get_pagenum_link( 999999999 ) ),
'format' => '',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $finalQuery->max_num_pages,
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3
) ) );
Remember not to change the code directly in the plugin folder.
Alexandre Leroux commented
Hi Pablo, thanks for your blog entry... however, it's difficult to follow! Could you post instructions in English please? Thanks for your contributions to solving this problem! -- Alex
I've made a post about a possible alternative:
I think we guys will have to use wp_query for this.
I did this way along with some modifications and it worked
i have been searching for a solution as well, also request this.
Categories may work fine with pagination as an alternative BUT 'recent products' and other such shortcodes really need pagination
Seeking this functionality at the moment. I'm guessing it can't be done? That's crazy!
WP & Woo are easy to easy. For DIY'ers like me I can't be messing around too much with category page templates etc.. I want to customize the look of a page using html/css shortcodes etc.. having a section where products are listed... with pagination.
I'v seen tons of shops that have several pages of a different layout, all listing products.. with pagination. so this appears to be something real.
lol been wanting this for like 2 years now
I second the need for this plugin or added functionality in woocommerce
khahina bijoux fantaisie (carole) commented
I have the same problem. i want all my products in one 'link' with pagination and use shortcode.
This suggest will be very usefull not only on product catégory but in all product short code.
like this [recent_products per_page="12" columns="3"]
Still having problems with this, and the solution of linking to categories is fine and does help, but then I end up having to go edit the category template anyways so I can include 12 rather than 10 products before pagination. (Is it just me, or does 10 NEVER work out to give the best product presentation? 2 rows of 5 doesn't usually fit with the themes I use. 3 rows of 3...plus one left over? 12 always works for me- 3 rows of 4 or 4 rows of 3- always works)
Anyways, it's definitely a problem, as I just had a random person email me for help with it after seeing my post about it in a forum.
Thank you for listening, Woo!
This plugin would solve a lot of other issues I am facing. There are clients that want to get rid of the shop page and just display certain categories on custom pages, but there is no pagination for those pages. This is something that even squarespace has the capability to do, and squarespace is horrible.
I would like to see this feature added as well. Or there should be a way we can put custom code into the description area of a particular category (instead of just plain text).
Ahmet H. commented
To who may be reading this at woocommerce. Although this feature request may not seem so important in the greater schema of things but it is!
Customizable selling pages targeted at specific categories and products with embedded short-code are a very simple and powerful way to implement these unique pages allowing customers to quickly find/buy. However without pagination it makes these pages unusable...
The alternative to this feature is to use the normal category pages and modify/add lot of php code to create customization so we can get pagination - this seams backwards for me.
I have three customers with over 900 products each running on woocommerce and this feature will not only help them but simplify my development for other potential customers.
By the way I think Woocommerce is great solution!!
It won't be adressed. Otherwise there would have been some heads up on it. There's a whole lot that hasn't been in this update. Some of these ideas are also suggesting way to much work that shouldn't need to happen. What you all are requesting is the obvious next thing.
Patrick Moore commented
I want to add my support for such a feature. Hard to believe this hasn't been addressed yet.